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

Fix premature session closure error #608

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

### Documentation 📝

### Bug fixes 🐛
### Bug fixes 🐛
* Fixed premature session closure when using `qiskit_session`.
[(#608)](https://github.com/PennyLaneAI/pennylane-qiskit/pull/608)

### Contributors ✍️

This release contains contributions from (in alphabetical order):

Andrija Paurevic
Tak Hur

---
# Release 0.39.1
Expand Down
1 change: 0 additions & 1 deletion pennylane_qiskit/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ def _function(*args, params: dict = None, wires: list = None, **kwargs):
mid_circ_regs[carg] = mid_circ_meas[-1]

else:

try:
if not isinstance(instruction, (ControlFlowOp,)):
operation_args = [instruction.to_matrix()]
Expand Down
6 changes: 3 additions & 3 deletions pennylane_qiskit/qiskit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
This module contains a prototype base class for constructing Qiskit devices
for PennyLane with the new device API.
"""
# pylint: disable=too-many-instance-attributes,attribute-defined-outside-init
# pylint: disable=too-many-instance-attributes,attribute-defined-outside-init,too-many-positional-arguments


import warnings
Expand Down Expand Up @@ -325,7 +325,6 @@ def __init__(
compile_backend=None,
**kwargs,
):

if shots is None:
warnings.warn(
"Expected an integer number of shots, but received shots=None. Defaulting "
Expand Down Expand Up @@ -592,7 +591,8 @@ def execute_circuits(session):
results.append(execute_fn(circ, session))
yield results
finally:
session.close()
if self._session is None:
session.close()

with execute_circuits(session) as results:
return results
Expand Down
1 change: 0 additions & 1 deletion pennylane_qiskit/qiskit_device_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
_eigs = {}

def __init__(self, wires, provider, backend, shots=1024, **kwargs):

super().__init__(wires=wires, shots=shots)

self.provider = provider
Expand Down Expand Up @@ -379,7 +378,7 @@
state = unitary @ initial_state

# reverse qubit order to match PennyLane convention
return state.reshape([2] * self.num_wires).T.flatten()

Check notice on line 381 in pennylane_qiskit/qiskit_device_legacy.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_qiskit/qiskit_device_legacy.py#L381

Possibly using variable 'state' before assignment (possibly-used-before-assignment)

def generate_samples(self, circuit=None):
r"""Returns the computational basis samples generated for all wires.
Expand Down
Loading