def test_parse_reset_qubit(): reset = """ RESET """.strip() parse_equals(reset, Reset()) reset_qubit = """ RESET 5 """.strip() parse_equals(reset_qubit, ResetQubit(Qubit(5)))
def RESET(qubit_index=None): """ Reset all qubits or just a specific qubit at qubit_index. :param Optional[int] qubit_index: The address of the qubit to reset. If None, reset all qubits. :returns: A Reset or ResetQubit Quil AST expression corresponding to a global or targeted reset, respectively. :rtype: Union[Reset, ResetQubit] """ if qubit_index is not None: return ResetQubit(Qubit(qubit_index)) else: return Reset()
def test_transform_with_post_transformation_hooks( bell_circuit_with_qids: Tuple[cirq.Circuit, List[cirq.Qid]], ) -> None: """test that a user can transform a `cirq.Circuit` to a `pyquil.Program` functionally with explicit physical qubit address mapping. """ bell_circuit, qubits = bell_circuit_with_qids def reset_hook(program, measurement_id_map): program._instructions.insert(0, Reset()) return program, measurement_id_map reset_hook_spec = create_autospec( reset_hook, side_effect=reset_hook, ) pragma = Pragma('INTIAL_REWIRING', freeform_string='GREEDY') def rewire_hook(program, measurement_id_map): program._instructions.insert(0, pragma) return program, measurement_id_map rewire_hook_spec = create_autospec( rewire_hook, side_effect=rewire_hook, ) transformer = transformers.build( qubits=tuple(qubits), post_transformation_hooks=[reset_hook_spec, rewire_hook_spec], ) program, _ = transformer(circuit=bell_circuit) assert 1 == reset_hook_spec.call_count assert Reset() in program.instructions, "hook should add reset" assert 1 == rewire_hook_spec.call_count assert pragma in program.instructions, "hook should add pragma" assert H(0) in program.instructions, "bell circuit should include Hadamard" assert CNOT(0, 1) in program.instructions, "bell circuit should include CNOT" assert ( DECLARE("m0", memory_size=2) in program.instructions ), "executable should declare a read out bit" assert ( MEASURE(0, ("m0", 0)) in program.instructions ), "executable should measure the first qubit to the first read out bit" assert ( MEASURE(1, ("m0", 1)) in program.instructions ), "executable should measure the second qubit to the second read out bit"
def RESET(qubit_index: Optional[QubitDesignator] = None) -> Union[Reset, ResetQubit]: """ Reset all qubits or just one specific qubit. :param qubit_index: The qubit to reset. This can be a qubit's index, a Qubit, or a QubitPlaceholder. If None, reset all qubits. :returns: A Reset or ResetQubit Quil AST expression corresponding to a global or targeted reset, respectively. """ if qubit_index is not None: return ResetQubit(unpack_qubit(qubit_index)) else: return Reset()
def RESET(qubit_index=None): """ Reset all qubits or just one specific qubit. :param Optional[Union[integer_types, Qubit, QubitPlaceholder]] qubit_index: The qubit to reset. This can be a qubit's index, a Qubit, or a QubitPlaceholder. If None, reset all qubits. :returns: A Reset or ResetQubit Quil AST expression corresponding to a global or targeted reset, respectively. :rtype: Union[Reset, ResetQubit] """ if qubit_index is not None: return ResetQubit(unpack_qubit(qubit_index)) else: return Reset()
def reset(self, qubit): if qubit: return ResetQubit(qubit) else: return Reset()
def reset_hook(program, measurement_id_map): program._instructions.insert(0, Reset()) return program, measurement_id_map
def exitResetState(self, ctx): # type: (QuilParser.ResetStateContext) -> None self.result.append(Reset())
def exitResetState(self, ctx): # type: (QuilParser.ResetStateContext) -> None if ctx.qubit(): self.result.append(ResetQubit(_qubit(ctx.qubit()))) else: self.result.append(Reset())
Produces a PSWAP instruction. This is a parameterized swap gate. :param angle: The angle of the phase to apply to the swapped states. This phase is applied to q1 when it is in the excited state and to q2 when it is in the ground state. :param q1: Qubit 1. :param q2: Qubit 2. :returns: A Gate object. """ WAIT = Wait() """ This instruction tells the quantum computation to halt. Typically these is used while classical memory is being manipulated by a CPU in a hybrid classical/quantum algorithm. :returns: A Wait object. """ RESET = Reset() """ This instruction resets all the qubits to the ground state. :returns: A Reset object. """ NOP = Nop() """ This instruction applies no operation at that timestep. Typically these are ignored in error-models. :returns: A Nop object. """ HALT = Halt() """ This instruction ends the program.