Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
eliottrosenberg committed Mar 2, 2025
1 parent 3f0b72e commit 3c13148
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cirq-core/cirq/transformers/gauge_compiling/cphase_gauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
)
from cirq import ops
import numpy as np
from typing import cast


class CPhasePauliGauge(Gauge):
Expand Down Expand Up @@ -56,7 +57,7 @@ def _get_new_post(self, exponent: float, pre: ops.Gate) -> ops.Gate:
raise ValueError("pre should be cirq.X or cirq.Y")

def _get_constant_gauge(
self, gate: ops.Gate, pre_q0: ops.Gate, pre_q1: ops.Gate
self, gate: ops.CZPowGate, pre_q0: ops.Gate, pre_q1: ops.Gate
) -> ConstantGauge:
"""Get the ConstantGauge corresponding to a given pre_q0 and pre_q1.
Expand Down Expand Up @@ -119,10 +120,15 @@ def sample(self, gate: ops.Gate, prng: np.random.Generator) -> ConstantGauge:
Returns:
A ConstantGauge implementing the transformation.
Raises:
TypeError: if gate is not a CZPowGate
"""

if not type(gate) == ops.CZPowGate:
raise TypeError("gate must be a CZPowGate")
pre_q0, pre_q1 = prng.choice(np.array([ops.I, ops.X, ops.Y, ops.Z]), size=2, replace=True)
return self._get_constant_gauge(gate, pre_q0, pre_q1)
return self._get_constant_gauge(cast(ops.CZPowGate, gate), pre_q0, pre_q1)


CPhaseGaugeSelector = GaugeSelector(gauges=[CPhasePauliGauge()])
Expand Down

0 comments on commit 3c13148

Please sign in to comment.