Skip to content
Merged
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
1 change: 1 addition & 0 deletions cirq-core/cirq/json_resolver_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def _symmetricalqidpair(qids):
'ParamResolver': cirq.ParamResolver,
'ParallelGate': cirq.ParallelGate,
'ParallelGateFamily': cirq.ParallelGateFamily,
'PauliInteractionGate': cirq.PauliInteractionGate,
'PauliMeasurementGate': cirq.PauliMeasurementGate,
'PauliString': cirq.PauliString,
'PauliStringPhasor': cirq.PauliStringPhasor,
Expand Down
1 change: 0 additions & 1 deletion cirq-core/cirq/ops/gate_operation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,6 @@ def all_subclasses(cls):
cirq.interop.quirk.QuirkArithmeticGate,
# No reason given for missing json.
# TODO(#5353): Serialize these gates.
cirq.PauliInteractionGate,
cirq.ArithmeticGate,
}

Expand Down
25 changes: 11 additions & 14 deletions cirq-core/cirq/ops/pauli_interaction_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Sequence, Tuple, cast, Dict, TYPE_CHECKING
from typing import Any, Dict, List, Sequence, TYPE_CHECKING, Tuple

import numpy as np

Expand All @@ -24,17 +24,11 @@
if TYPE_CHECKING:
import cirq

pauli_eigen_map = cast(
Dict[pauli_gates.Pauli, np.ndarray],
{
pauli_gates.X: (np.array([[0.5, 0.5], [0.5, 0.5]]), np.array([[0.5, -0.5], [-0.5, 0.5]])),
pauli_gates.Y: (
np.array([[0.5, -0.5j], [0.5j, 0.5]]),
np.array([[0.5, 0.5j], [-0.5j, 0.5]]),
),
pauli_gates.Z: (np.diag([1, 0]), np.diag([0, 1])),
},
)
PAULI_EIGEN_MAP: Dict[pauli_gates.Pauli, np.ndarray] = {
pauli_gates.X: (np.array([[0.5, 0.5], [0.5, 0.5]]), np.array([[0.5, -0.5], [-0.5, 0.5]])),
pauli_gates.Y: (np.array([[0.5, -0.5j], [0.5j, 0.5]]), np.array([[0.5, 0.5j], [-0.5j, 0.5]])),
pauli_gates.Z: (np.diag([1, 0]), np.diag([0, 1])),
}


@value.value_equality
Expand Down Expand Up @@ -108,8 +102,8 @@ def _eigen_shifts(self) -> List[float]:

def _eigen_components(self) -> List[Tuple[float, np.ndarray]]:
comp1 = np.kron(
pauli_eigen_map[self.pauli0][not self.invert0],
pauli_eigen_map[self.pauli1][not self.invert1],
PAULI_EIGEN_MAP[self.pauli0][not self.invert0],
PAULI_EIGEN_MAP[self.pauli1][not self.invert1],
)
comp0 = np.eye(4) - comp1
return [(0, comp0), (1, comp1)]
Expand Down Expand Up @@ -153,6 +147,9 @@ def __repr__(self) -> str:
return base
return f'({base}**{proper_repr(self._exponent)})'

def _json_dict_(self) -> Dict[str, Any]:
return protocols.obj_to_dict_helper(self, ["pauli0", "invert0", "pauli1", "invert1"])


PauliInteractionGate.CZ = PauliInteractionGate(pauli_gates.Z, False, pauli_gates.Z, False)
PauliInteractionGate.CNOT = PauliInteractionGate(pauli_gates.Z, False, pauli_gates.X, False)
15 changes: 15 additions & 0 deletions cirq-core/cirq/protocols/json_test_data/PauliInteractionGate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"cirq_type": "PauliInteractionGate",
"pauli0": {
"cirq_type": "_PauliZ",
"exponent": 1.0,
"global_shift": 0.0
},
"invert0": false,
"pauli1": {
"cirq_type": "_PauliX",
"exponent": 1.0,
"global_shift": 0.0
},
"invert1": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cirq.PauliInteractionGate(cirq.Z, False, cirq.X, True)
1 change: 0 additions & 1 deletion cirq-core/cirq/protocols/json_test_data/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
'Linspace',
'ListSweep',
'NeutralAtomDevice',
'PauliInteractionGate',
'PauliSumCollector',
'PauliSumExponential',
'PauliTransform',
Expand Down