def _strat_apply_gate(self, val: Any, qubits: Sequence['cirq.Qid']) -> bool:
     if not protocols.has_stabilizer_effect(val):
         return NotImplemented
     gate = val.gate if isinstance(val, ops.Operation) else val
     axes = self.get_axes(qubits)
     exponent = cast(float, getattr(gate, 'exponent', None))
     if isinstance(gate, common_gates.XPowGate):
         self._state.apply_x(axes[0], exponent, gate.global_shift)
     elif isinstance(gate, common_gates.YPowGate):
         self._state.apply_y(axes[0], exponent, gate.global_shift)
     elif isinstance(gate, common_gates.ZPowGate):
         self._state.apply_z(axes[0], exponent, gate.global_shift)
     elif isinstance(gate, common_gates.HPowGate):
         self._state.apply_h(axes[0], exponent, gate.global_shift)
     elif isinstance(gate, common_gates.CXPowGate):
         self._state.apply_cx(axes[0], axes[1], exponent, gate.global_shift)
     elif isinstance(gate, common_gates.CZPowGate):
         self._state.apply_cz(axes[0], axes[1], exponent, gate.global_shift)
     elif isinstance(gate, global_phase_op.GlobalPhaseGate):
         if isinstance(gate.coefficient, sympy.Expr):
             return NotImplemented
         self._state.apply_global_phase(gate.coefficient)
     elif isinstance(gate, swap_gates.SwapPowGate):
         self._swap(axes[0], axes[1], exponent, gate.global_shift)
     else:
         return NotImplemented
     return True
 def _strat_decompose(self, val: Any, qubits: Sequence['cirq.Qid']) -> bool:
     gate = val.gate if isinstance(val, ops.Operation) else val
     operations = protocols.decompose_once_with_qubits(gate, qubits, None)
     if operations is None or not all(protocols.has_stabilizer_effect(op) for op in operations):
         return NotImplemented
     for op in operations:
         protocols.act_on(op, self)
     return True
Example #3
0
 def is_supported_operation(op: 'cirq.Operation') -> bool:
     """Checks whether given operation can be simulated by this simulator."""
     # TODO: support more general Pauli measurements
     return protocols.has_stabilizer_effect(op)