diff --git a/setup.py b/setup.py index 8282a24..e07a143 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ ], setup_requires=["setuptools_scm~=6.0"], install_requires=[ - "qiskit~=0.28", + "qiskit>=0.28, <0.34", "qiskit-ibmq-provider~=0.15", "symengine~=0.7", "numpy~=1.0", diff --git a/src/python/qeqiskit/backend/backend.py b/src/python/qeqiskit/backend/backend.py index 91ac4b6..394eda2 100644 --- a/src/python/qeqiskit/backend/backend.py +++ b/src/python/qeqiskit/backend/backend.py @@ -1,6 +1,6 @@ import math import time -from typing import List, Optional, Tuple +from typing import List, Optional, Sequence, Tuple from qeqiskit.conversions import export_to_qiskit from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister, execute @@ -86,13 +86,14 @@ def run_circuit_and_measure(self, circuit: Circuit, n_samples: int) -> Measureme circuit: the circuit to prepare the state n_samples: The number of samples to collect. """ - assert isinstance(n_samples, int) and n_samples > 0 + if n_samples <= 0: + raise ValueError("n_samples should be greater than 0.") return self.run_circuitset_and_measure([circuit], [n_samples])[0] def transform_circuitset_to_ibmq_experiments( self, circuitset: List[Circuit], - n_samples: List[int], + n_samples: Sequence[int], ) -> Tuple[List[QuantumCircuit], List[int], List[int]]: """Convert circuits to qiskit and duplicate those whose measurement count exceeds the maximum allowed by the backend. @@ -244,7 +245,7 @@ def aggregregate_measurements( def run_circuitset_and_measure( self, circuits: List[Circuit], - n_samples: List[int], + n_samples: Sequence[int], ) -> List[Measurements]: """Run a set of circuits and measure a certain number of bitstrings. Note: the number of bitstrings measured is derived from self.n_samples @@ -258,8 +259,6 @@ def run_circuitset_and_measure( A list of Measurements objects containing the observed bitstrings. """ - assert isinstance(n_samples, list) - assert isinstance(n_samples[0], int) ( experiments, n_samples_for_experiments, diff --git a/tests/qeqiskit/backend/backend_test.py b/tests/qeqiskit/backend/backend_test.py index 589b778..e416f91 100644 --- a/tests/qeqiskit/backend/backend_test.py +++ b/tests/qeqiskit/backend/backend_test.py @@ -206,10 +206,7 @@ def test_run_circuitset_and_measure_split_circuits_and_jobs(self, backend): # Given num_circuits = 200 circuit = self.x_cnot_circuit() - n_samples = 20001 - - # Verify that we are actually going to need to split circuits - assert n_samples > backend.max_shots + n_samples = backend.max_shots + 1 # Verify that we are actually going to need multiple batches assert ( diff --git a/tests/qeqiskit/conversion/circuit_conversions_test.py b/tests/qeqiskit/conversion/circuit_conversions_test.py index 4245410..9792445 100644 --- a/tests/qeqiskit/conversion/circuit_conversions_test.py +++ b/tests/qeqiskit/conversion/circuit_conversions_test.py @@ -144,13 +144,21 @@ def _make_qiskit_circuit(n_qubits, commands): SYMPY_THETA = sympy.Symbol("theta") SYMPY_GAMMA = sympy.Symbol("gamma") SYMPY_LAMBDA = sympy.Symbol("lambda_") +SYMPY_PARAMETER_VECTOR = [sympy.Symbol("p[0]"), sympy.Symbol("p[1]")] QISKIT_THETA = qiskit.circuit.Parameter("theta") QISKIT_GAMMA = qiskit.circuit.Parameter("gamma") QISKIT_LAMBDA = qiskit.circuit.Parameter("lambda_") +QISKIT_PARAMETER_VECTOR = qiskit.circuit.ParameterVector("p", 2) -EXAMPLE_PARAM_VALUES = {"gamma": 0.3, "theta": -5, "lambda_": np.pi / 5} +EXAMPLE_PARAM_VALUES = { + "gamma": 0.3, + "theta": -5, + "lambda_": np.pi / 5, + "p[0]": -5, + "p[1]": 0.3, +} EQUIVALENT_NON_PARAMETRIZED_CIRCUITS = [ @@ -331,6 +339,22 @@ def _make_qiskit_circuit(n_qubits, commands): ], ), ), + ( + _circuit.Circuit( + [ + _builtin_gates.RX( + SYMPY_PARAMETER_VECTOR[0] * SYMPY_PARAMETER_VECTOR[1] + )(1), + ], + 4, + ), + _make_qiskit_circuit( + 4, + [ + ("rx", (QISKIT_PARAMETER_VECTOR[0] * QISKIT_PARAMETER_VECTOR[1], 1)), + ], + ), + ), ]