Skip to content

Commit

Permalink
BugFix: support for Identity on multiple wires
Browse files Browse the repository at this point in the history
  • Loading branch information
astralcai committed Apr 22, 2024
1 parent c7cfefe commit 1cee18c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pennylane_cirq/cirq_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(self, wires, shots, qubits=None):
"Hermitian": None,
# TODO: Consider using qml.utils.decompose_hamiltonian() to support this observable.
"Prod": None,
"Identity": CirqOperation(lambda: cirq.I),
"Identity": CirqOperation(lambda *args: cirq.IdentityGate(*args)),

Check notice on line 174 in pennylane_cirq/cirq_device.py

View check run for this annotation

codefactor.io / CodeFactor

pennylane_cirq/cirq_device.py#L174

Lambda may not be necessary (unnecessary-lambda)
"Projector": CirqOperation(lambda: cirq.ProductState.projector),
}

Expand Down Expand Up @@ -200,7 +200,12 @@ def to_paulistring(self, observable):
cirq_op = self._observable_map[observable.name]
if cirq_op is None:
raise NotImplementedError(f"{observable.name} is not currently supported.")
cirq_op.parametrize(*observable.parameters)
parameters = (
[len(observable.wires)]
if isinstance(observable, qml.Identity)
else observable.parameters
)
cirq_op.parametrize(*parameters)
device_wires = self.map_wires(observable.wires)
return functools.reduce(
operator.mul, cirq_op.apply(*[self.qubits[w] for w in device_wires.labels])
Expand Down

0 comments on commit 1cee18c

Please sign in to comment.