Skip to content

Commit

Permalink
BugFix: support for Identity on multiple wires (#186)
Browse files Browse the repository at this point in the history
* BugFix: support for Identity on multiple wires

* remove unnecessary lambda
  • Loading branch information
astralcai authored Apr 22, 2024
1 parent c7cfefe commit d899426
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(cirq.IdentityGate),
"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 d899426

Please sign in to comment.