Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle batch execution of no circuits #459

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

### Improvements 🛠

* The UI for passing parameters to a ``qfunc`` generated when loading a Qiskit ``QuantumCircuit``
* The UI for passing parameters to a `qfunc` generated when loading a Qiskit `QuantumCircuit`
into PennyLane is updated to allow passing parameters as args or kwargs, rather than as
a dictionary. The old dictionary UI continues to be supported.
[(#406)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/406)
[(#428)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/428)

* Measurement operations are now added to the PennyLane template when a ``QuantumCircuit``
* Measurement operations are now added to the PennyLane template when a `QuantumCircuit`
is converted using `load`. Additionally, one can override any existing terminal
measurements by providing a list of PennyLane
`measurements <https://docs.pennylane.ai/en/stable/introduction/measurements.html>`_ themselves.
[(#405)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/405)
[(#466)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/466)

* Added the support for converting conditional operations based on mid-circuit measurements and
two of the ``ControlFlowOp`` operations - ``IfElseOp`` and ``SwitchCaseOp`` when converting
a ``QuantumCircuit`` using `load`.
two of the `ControlFlowOp` operations - `IfElseOp` and `SwitchCaseOp` when converting
a `QuantumCircuit` using `load`.
[(#417)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/417)
[(#465)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/465)

* Qiskit's classical ``Expr`` conditionals can also be used with the supported
``ControlFlowOp`` operations.
* Qiskit's classical `Expr` conditionals can also be used with the supported
`ControlFlowOp` operations.
[(#432)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/432)

* Added conversion support for more Qiskit gates to native PennyLane operations -
``Barrier``, ``CYGate``, ``CHGate``, ``CPhase``, ``CCZGate``, ``ECRGate``, and ``GlobalPhaseGate``.
`Barrier`, `CYGate`, `CHGate`, `CPhase`, `CCZGate`, `ECRGate`, and `GlobalPhaseGate`.
[(#449)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/449)

* Added the ability to convert a Qiskit `SparsePauliOp` instance into a PennyLane `Operator`.
Expand All @@ -49,6 +49,9 @@

### Bug fixes 🐛

* `QiskitDevice.batch_execute()` now gracefully handles empty lists of circuits.
[(#459)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/459)

* It is now possible to compute the gradient of a circuit with `ParameterVector` elements.
[(#458)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/458)

Expand Down Expand Up @@ -477,7 +480,7 @@ Christina Lee, Antal Száva

### Improvements

* The plugin can now load Qiskit circuits with more complicated ``ParameterExpression`` variables.
* The plugin can now load Qiskit circuits with more complicated `ParameterExpression` variables.
[(#139)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/139)

### Contributors
Expand Down Expand Up @@ -629,7 +632,7 @@ Maria Schuld, Antal Száva

### Improvements

* Ported the ``QiskitDevice`` class to inherit from the ``QubitDevice`` class
* Ported the `QiskitDevice` class to inherit from the `QubitDevice` class
defined in PennyLane to use unified qubit operations and ease development.
[(#83)](https://github.com/XanaduAI/pennylane-qiskit/pull/83)

Expand Down
4 changes: 4 additions & 0 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ def batch_execute(self, circuits, timeout: int = None):

compiled_circuits = self.compile_circuits(circuits)

if not compiled_circuits:
# At least one circuit must always be provided to the backend.
return []

# Send the batch of circuit objects using backend.run
self._current_job = self.backend.run(compiled_circuits, shots=self.shots, **self.run_args)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def test_result(self, device, tol):
assert isinstance(res[1], np.ndarray)
assert np.allclose(res[1], tape2_expected, atol=0)

def test_result_no_tapes(self, device):
"""Tests that the result is correct when there are no tapes to execute."""
dev = device(2)
res = dev.batch_execute([])

# We're calling device methods directly, need to reset before the next
# execution
dev.reset()
assert not res

def test_result_empty_tape(self, device, tol):
"""Tests that the result has the correct shape and entry types for
empty tapes."""
Expand Down
Loading