Skip to content

Commit

Permalink
Bugfix/lightning nobin (#5349)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      test directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [x] Ensure that the test suite passes, by running `make test`.

- [ ] Add a new entry to the `doc/releases/changelog-dev.md` file,
summarizing the
      change, and including a link back to the PR.

- [x] The PennyLane source code conforms to
      [PEP8 standards](https://www.python.org/dev/peps/pep-0008/).
We check all of our code against [Pylint](https://www.pylint.org/).
      To lint modified files, simply `pip install pylint`, and then
      run `pylint pennylane/path/to/file.py`.

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**
The no-bin Lightning which derives from Device fails shots tests due to
the new condition.

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
  • Loading branch information
vincentmr authored Mar 11, 2024
1 parent b7080cc commit db2fb6d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pennylane/_qubit_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,19 @@ def execute(self, circuit, **kwargs):
sample_type = (SampleMP, CountsMP, ClassicalShadowMP, ShadowExpvalMP)
if self.shots is not None or any(isinstance(m, sample_type) for m in circuit.measurements):
# Lightning does not support apply(rotations) anymore, so we need to rotate here
# Lightning without binaries fallbacks to `QubitDevice`, and hence the _CPP_BINARY_AVAILABLE condition
is_lightning = (
hasattr(self, "name") and isinstance(self.name, str) and "Lightning" in self.name
hasattr(self, "name")
and isinstance(self.name, str)
and "Lightning" in self.name
and getattr(self, "_CPP_BINARY_AVAILABLE", False)
)
diagonalizing_gates = self._get_diagonalizing_gates(circuit) if is_lightning else None
if is_lightning and diagonalizing_gates:
self.apply_lightning(diagonalizing_gates)
self.apply(diagonalizing_gates)
self._samples = self.generate_samples()
if is_lightning and diagonalizing_gates:
self.apply_lightning(
[qml.adjoint(g, lazy=False) for g in reversed(diagonalizing_gates)]
)
self.apply([qml.adjoint(g, lazy=False) for g in reversed(diagonalizing_gates)])

# compute the required statistics
if self._shot_vector is not None:
Expand Down

0 comments on commit db2fb6d

Please sign in to comment.