Skip to content

Commit

Permalink
Merge pull request #84 from zapatacomputing/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
mstechly authored Jan 13, 2022
2 parents 7b0cb0e + 1616b65 commit 15f05a7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 5 additions & 6 deletions src/python/qeqiskit/backend/backend.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions tests/qeqiskit/backend/backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
26 changes: 25 additions & 1 deletion tests/qeqiskit/conversion/circuit_conversions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)),
],
),
),
]


Expand Down

0 comments on commit 15f05a7

Please sign in to comment.