Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_all_resolved(self, circuit):
"""Raises if the circuit contains unresolved symbols."""
if protocols.is_parameterized(circuit):
unresolved = [
op for moment in circuit for op in moment
if protocols.is_parameterized(op)
]
raise ValueError(
'Circuit contains ops whose symbols were not specified in '
'parameter sweep. Ops: {}'.format(unresolved))
the result is considered ambiguous and an error is thrown. If no angle
argument is given, the default value of one half turn is used.
If pauli_string is negative, the sign is transferred to the phase.
Args:
pauli_string: The PauliString to phase.
half_turns: Phasing of the Pauli string, in half_turns.
rads: Phasing of the Pauli string, in radians.
degs: Phasing of the Pauli string, in degrees.
"""
half_turns = value.chosen_angle_to_half_turns(
half_turns=half_turns,
rads=rads,
degs=degs)
if not protocols.is_parameterized(half_turns):
half_turns = 1 - (1 - half_turns) % 2
super().__init__(pauli_string)
self.half_turns = half_turns
def _formatted_exponent(info: 'cirq.CircuitDiagramInfo',
args: 'cirq.CircuitDiagramInfoArgs') -> Optional[str]:
if protocols.is_parameterized(info.exponent):
name = str(info.exponent)
return ('({})'.format(name)
if _is_exposed_formula(name)
else name)
if info.exponent == 0:
return '0'
# 1 is not shown.
if info.exponent == 1:
return None
# Round -1.0 into -1.
if info.exponent == -1:
return '-1'
def _is_parameterized_(self) -> bool:
return protocols.is_parameterized(self._exponent)
def _is_parameterized_(self) -> bool:
"""See `cirq.SupportsParameterization`."""
return (protocols.is_parameterized(self._exponent) or
protocols.is_parameterized(self._phase_exponent))
def _check_all_resolved(self, circuit):
"""Raises if the circuit contains unresolved symbols."""
if protocols.is_parameterized(circuit):
unresolved = [
op for moment in circuit for op in moment
if protocols.is_parameterized(op)
]
raise ValueError(
'Circuit contains ops whose symbols were not specified in '
'parameter sweep. Ops: {}'.format(unresolved))
def __repr__(self) -> str:
if self._global_shift == -0.5 and not protocols.is_parameterized(self):
if self._exponent == 1:
return 'cirq.ms(np.pi/2)'
return 'cirq.ms({!r}*np.pi/2)'.format(self._exponent)
if self._global_shift == 0:
if self._exponent == 1:
return 'cirq.XX'
return '(cirq.XX**{})'.format(proper_repr(self._exponent))
return ('cirq.XXPowGate(exponent={}, '
'global_shift={!r})'
).format(proper_repr(self._exponent), self._global_shift)
def _is_parameterized_(self) -> bool:
return protocols.is_parameterized(self.gate)
def _is_parameterized_(self) -> bool:
if protocols.is_parameterized(self._iswap):
return True
return protocols.is_parameterized(self._phase_exponent)
def _pauli_expansion_(self) -> value.LinearDict[str]:
if protocols.is_parameterized(self):
return NotImplemented
a = math.cos(self.theta)
b = -1j * math.sin(self.theta)
c = cmath.exp(-1j * self.phi)
return value.LinearDict({
'II': (1 + c) / 4 + a / 2,
'IZ': (1 - c) / 4,
'ZI': (1 - c) / 4,
'ZZ': (1 + c) / 4 - a / 2,
'XX': b / 2,
'YY': b / 2,
})