Skip to content

Commit

Permalink
add support for single circuit on exeuctor run method (unitaryfund#2099)
Browse files Browse the repository at this point in the history
* add support for single circuit on exeuctor run method

* upate authors list

* downgrade qiskit_aer version due to incompatibilities

DiagonalGate cannot be imported with version 0.13

* add single circuit tests to run method of executor

* run black on addded tests
  • Loading branch information
EmilianoG-byte committed Dec 1, 2023
1 parent 082cd06 commit c8b6425
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ Mohammad Zuhair Khan
Brian Goldsmith
Farzad Kianvash
Yash Prabhat
Vladimir Kozhukalov
Vladimir Kozhukalov
Emiliano Godinez
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Third-party integration.
qiskit~=0.44.3
qiskit-aer~=0.13.0
qiskit-aer~=0.12.2
qiskit-ibm-provider~=0.7.2
pyquil~=3.5.4
pennylane-qiskit~=0.33.0
Expand Down
7 changes: 5 additions & 2 deletions mitiq/executor/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,22 @@ def evaluate(

def run(
self,
circuits: Sequence[QPROGRAM],
circuits: Union[QPROGRAM, Sequence[QPROGRAM]],
force_run_all: bool = True,
**kwargs: Any,
) -> Sequence[QuantumResult]:
"""Runs all input circuits using the least number of possible calls to
the executor.
Args:
circuits: Sequence of circuits to execute using the executor.
circuits: Circuit or sequence thereof to execute with the executor.
force_run_all: If True, force every circuit in the input sequence
to be executed (if some are identical). Else, detects identical
circuits and runs a minimal set.
"""
if not isinstance(circuits, Sequence):
circuits = [circuits]

start_result_index = len(self._quantum_results)

if force_run_all:
Expand Down
9 changes: 9 additions & 0 deletions mitiq/executor/tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ def test_executor_non_hermitian_observable():
executor.evaluate(circuits, obs)


def test_run_executor_single_circuit():
collector = Executor(executor=executor_serial)
circuit = cirq.Circuit(cirq.H(cirq.LineQubit(0)))
results_no_sequence = collector.run(circuit)
results_sequence = collector.run([circuit])
assert np.allclose(results_no_sequence, np.zeros(1))
assert np.allclose(results_no_sequence, results_sequence)


@pytest.mark.parametrize("ncircuits", (5, 10, 25))
@pytest.mark.parametrize("executor", (executor_batched, executor_serial))
def test_run_executor_identical_circuits_batched(ncircuits, executor):
Expand Down

0 comments on commit c8b6425

Please sign in to comment.