def __init__(self, qubit_map, initial_state=0): self.qubit_map = qubit_map self.n = len(qubit_map) self.tableau = clifford_tableau.CliffordTableau(self.n, initial_state) self.ch_form = stabilizer_state_ch_form.StabilizerStateChForm( self.n, initial_state)
def _final_stabilizer_state_ch_form( circuit: Circuit, qubit_map) -> Optional[stabilizer_state_ch_form.StabilizerStateChForm]: """Evolves a default StabilizerStateChForm through the input circuit. Initializes a StabilizerStateChForm with default args for the given qubits and evolves it by having each operation act on the state. Args: circuit: An input circuit that acts on the zero state qubit_map: A map from qid to the qubit index for the above circuit Returns: None if any of the operations can not act on a StabilizerStateChForm, returns the StabilizerStateChForm otherwise.""" stabilizer_ch_form = stabilizer_state_ch_form.StabilizerStateChForm( len(qubit_map)) args = stabilizer_ch_form_simulation_state.StabilizerChFormSimulationState( qubits=list(qubit_map.keys()), prng=np.random.RandomState(), initial_state=stabilizer_ch_form, ) for op in circuit.all_operations(): try: protocols.act_on(op, args, allow_decompose=True) except TypeError: return None return stabilizer_ch_form
def _final_stabilizer_state_ch_form( circuit: Circuit, qubit_map) -> Optional[stabilizer_state_ch_form.StabilizerStateChForm]: """Evolves a default StabilizerStateChForm through the input circuit. Initializes a StabilizerStateChForm with default args for the given qubits and evolves it by having each operation act on the state. Args: circuit: An input circuit that acts on the zero state qubit_map: A map from qid to the qubit index for the above circuit Returns: None if any of the operations can not act on a StabilizerStateChForm, returns the StabilizerStateChForm otherwise.""" stabilizer_ch_form = stabilizer_state_ch_form.StabilizerStateChForm( len(qubit_map)) for op in circuit.all_operations(): try: args = act_on_stabilizer_ch_form_args.ActOnStabilizerCHFormArgs( state=stabilizer_ch_form, axes=[qubit_map[qid] for qid in op.qubits], prng=np.random.RandomState(), log_of_measurement_results={}, ) protocols.act_on(op, args, allow_decompose=True) except TypeError: return None return stabilizer_ch_form
def __init__( self, state: Optional['cirq.StabilizerStateChForm'] = None, prng: Optional[np.random.RandomState] = None, log_of_measurement_results: Optional[Dict[str, List[int]]] = None, qubits: Optional[Sequence['cirq.Qid']] = None, initial_state: Union[int, 'cirq.StabilizerStateChForm'] = 0, classical_data: Optional['cirq.ClassicalDataStore'] = None, ): """Initializes with the given state and the axes for the operation. Args: state: The StabilizerStateChForm to act on. Operations are expected to perform inplace edits of this object. qubits: Determines the canonical ordering of the qubits. This is often used in specifying the initial state, i.e. the ordering of the computational basis states. prng: The pseudo random number generator to use for probabilistic effects. log_of_measurement_results: A mutable object that measurements are being recorded into. initial_state: The initial state for the simulation. This can be a full CH form passed by reference which will be modified inplace, or a big-endian int in the computational basis. If the state is an integer, qubits must be provided in order to determine array sizes. classical_data: The shared classical data container for this simulation. Raises: ValueError: If initial state is an integer but qubits are not provided. """ initial_state = state or initial_state if isinstance(initial_state, int): if qubits is None: raise ValueError( 'Must specify qubits if initial state is integer') initial_state = stabilizer_state_ch_form.StabilizerStateChForm( len(qubits), initial_state) super().__init__( state=initial_state, prng=prng, qubits=qubits, log_of_measurement_results=log_of_measurement_results, classical_data=classical_data, )