How to use the cirq.protocols.is_parameterized function in cirq

To help you get started, we’ve selected a few cirq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github quantumlib / Cirq / cirq / sim / sparse_simulator.py View on Github external
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))
github quantumlib / Cirq / cirq / contrib / paulistring / pauli_string_phasor.py View on Github external
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
github quantumlib / Cirq / cirq / circuits / circuit.py View on Github external
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'
github quantumlib / Cirq / cirq / ops / eigen_gate.py View on Github external
def _is_parameterized_(self) -> bool:
        return protocols.is_parameterized(self._exponent)
github quantumlib / Cirq / cirq / ops / phased_x_gate.py View on Github external
def _is_parameterized_(self) -> bool:
        """See `cirq.SupportsParameterization`."""
        return (protocols.is_parameterized(self._exponent) or
                protocols.is_parameterized(self._phase_exponent))
github quantumlib / Cirq / cirq / sim / sparse_simulator.py View on Github external
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))
github quantumlib / Cirq / cirq / ops / parity_gates.py View on Github external
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)
github quantumlib / Cirq / cirq / ops / parallel_gate_operation.py View on Github external
def _is_parameterized_(self) -> bool:
        return protocols.is_parameterized(self.gate)
github quantumlib / Cirq / cirq / ops / phased_iswap_gate.py View on Github external
def _is_parameterized_(self) -> bool:
        if protocols.is_parameterized(self._iswap):
            return True
        return protocols.is_parameterized(self._phase_exponent)
github ngnrsaa / qflex / python / cirq_interface / fsim_gate.py View on Github external
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,
        })