From 1cee18c533234cb5820cb94ddc1158ddd2d44fa7 Mon Sep 17 00:00:00 2001 From: Astral Cai Date: Mon, 22 Apr 2024 11:18:36 -0400 Subject: [PATCH] BugFix: support for Identity on multiple wires --- pennylane_cirq/cirq_device.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pennylane_cirq/cirq_device.py b/pennylane_cirq/cirq_device.py index a5e367b..848021a 100644 --- a/pennylane_cirq/cirq_device.py +++ b/pennylane_cirq/cirq_device.py @@ -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)), "Projector": CirqOperation(lambda: cirq.ProductState.projector), } @@ -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])