From 45d71e8fba08440e187c7e2c1ebcd82a4f4a2a76 Mon Sep 17 00:00:00 2001 From: otkulseng Date: Sun, 8 Jun 2025 13:04:30 +0200 Subject: [PATCH] tests and doi fix --- CONTRIBUTING.md | 5 ++++- README.md | 5 +++++ paper.bib | 1 + paper.md | 3 +-- setup.py | 4 ++-- tests/test_imports.py | 7 +++++++ tests/test_run.py | 34 ++++++++++++++++++++++++++++++++++ 7 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 tests/test_imports.py create mode 100644 tests/test_run.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c5bb93f..044c531 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,10 @@ Thank you for considering contributing! We welcome all kinds of contributions— --- ## How to Contribute -Feel free to submit a "pull request" on GitHub in a designated feature branch. Include comments about what the fix/update does. +Feel free to submit a "pull request" on GitHub in a designated feature branch. Include comments about what the fix/update does, and ensure the tests work by running: +```python +states = res.run(timeseries) +``` For new features, please also consider updating the examples folder to show the intended use of the feature. diff --git a/README.md b/README.md index 86b9150..48991b4 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,11 @@ This will return a `np.ndarray` of the same length as the timeseries, correspond `Incremental` reservoirs run incrementally. For every state, only the last `M` steps of the timeseries is built at a time (`M` being a parameter of `Incremental.__init__`). +## Testing +Some tests have been implemented using pytest. To run them, ensure pytest is installed (*not* installed as runtime dependency) and run +```python +pytest +``` ## About You can find out more about QuantumReservoirPy and contact the authors [here](https://quantumreservoirpy.readthedocs.io/en/latest/about/). diff --git a/paper.bib b/paper.bib index fd3a872..dbb4fcc 100644 --- a/paper.bib +++ b/paper.bib @@ -16,6 +16,7 @@ @InProceedings{trouvain20 and Pedrelli, Luca and Dinh, Thanh Trung and Hinaut, Xavier", +doi = {10.1007/978-3-030-61616-8_40}, editor="Farka{\v{s}}, Igor and Masulli, Paolo and Wermter, Stefan", diff --git a/paper.md b/paper.md index 24c9e16..23637d6 100644 --- a/paper.md +++ b/paper.md @@ -78,8 +78,7 @@ The processing methods do not affect the creation of the reservoirs, but are inc ## Dependencies -The three main dependencies of `QuantumReservoirPy` are numpy, qiskit, and scikit-learn. -We strive for `QuantumReservoirPy` to support compatibility with existing reservoir computing and quantum computing workflows. +The three main dependencies of `QuantumReservoirPy` are numpy, qiskit, and scikit-learn, with python versions above 3.9. Qiskit is [deprecating](https://github.com/Qiskit/qiskit/releases) python 3.9 support in the 2.1.0 version, and the package presented here is developed to support qiskit=2.0.x. As for the other packages, the supported versions of scikit-learn and numpy follows from their interrelated constraints as well as the constraint from qiskit. In the install script, we specify numpy>1.17. We strive for `QuantumReservoirPy` to support compatibility with existing reservoir computing and quantum computing workflows. Much of existing research in QRC is performed on IBM devices and simulators (see [@yasuda23; @suzuki22]), programmed through the Qiskit software package. To minimize disruption in current workflows, `QuantumReservoirPy` is built as a package to interact with Qiskit circuits and backends. It is expected that the user also use Qiskit in the customization of reservoir architecture when working with `QuantumReservoirPy`. diff --git a/setup.py b/setup.py index 529dc54..ba684a7 100644 --- a/setup.py +++ b/setup.py @@ -4,9 +4,9 @@ "matplotlib", "tqdm", "pylatexenc>=2.0", - "qiskit>=1.0", + "qiskit<2.1.0", "qiskit-aer>=0.12.0", - "numpy>=1.21.6", + "numpy>=1.17", "scikit-learn", "ipykernel" ] diff --git a/tests/test_imports.py b/tests/test_imports.py new file mode 100644 index 0000000..0255071 --- /dev/null +++ b/tests/test_imports.py @@ -0,0 +1,7 @@ +def test_import_main(): + import quantumreservoirpy + +def test_import_submodules(): + from quantumreservoirpy import music + from quantumreservoirpy import reservoirs + from quantumreservoirpy import plot \ No newline at end of file diff --git a/tests/test_run.py b/tests/test_run.py new file mode 100644 index 0000000..945d435 --- /dev/null +++ b/tests/test_run.py @@ -0,0 +1,34 @@ + + +def test_incremental(): + import numpy as np + from qiskit.quantum_info import random_unitary + from quantumreservoirpy.reservoirs import Incremental + + encoder = {0: "00", 1: "01", 2: "10", 3: "11"} + SHOTS = 100 + + + class RandomUnitary(Incremental): + def __init__(self, n_qubits, memory=np.inf, backend=None, num_features=8) -> None: + super().__init__(n_qubits, memory, backend, num_features) + self.operator = random_unitary(2**n_qubits) + + def before(self, circuit): + circuit.h(circuit.qubits) + + def during(self, circuit, timestep, reservoirnumber): + circuit.measure([0, 1]) + circuit.initialize(encoder[timestep], [0, 1]) + circuit.append(self.operator, circuit.qubits) + + def after(self, circuit): + circuit.measure_all() + + + res = RandomUnitary(n_qubits=4, memory=8) + + timestep = [0, 1, 2, 3, 0, 1, 2, 2, 3] + timeseries = timestep * 10 + + res.run(timeseries, shots=SHOTS) \ No newline at end of file