# pyquil.gates¶

A lovely bunch of gates and instructions for programming with. This module is used to provide Pythonic sugar for Quil instructions.

pyquil.gates.AND(classical_reg1, classical_reg2)[source]

Produce an AND instruction.

Parameters: classical_reg1 – The first classical register. classical_reg2 – The second classical register, which gets modified. A ClassicalAnd instance.
pyquil.gates.CCNOT(*qubits)

Produces a CCNOT instruction. This gate applies to three qubit arguments to produce the controlled-controlled-not gate instruction.

Parameters: control-1 – The first control qubit. control-2 – The second control qubit. target – The target qubit. The target qubit has an X-gate applied to it if both control qubits are in the excited state. A Gate object.
pyquil.gates.CNOT(*qubits)

Produces a CNOT instruction. This gate applies to two qubit arguments to produce the controlled-not gate instruction.

Parameters: control – The control qubit. target – The target qubit. The target qubit has an X-gate applied to it if the control qubit is in the excited state. A Gate object.
pyquil.gates.CPHASE(*params)

Produces a CPHASE00 instruction. This gate applies to two qubit arguments to produce one of the controlled phase instructions.

Parameters: angle – The input phase angle to apply when both qubits are in the excited state. q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.CPHASE00(*params)

Produces a CPHASE00 instruction. This gate applies to two qubit arguments to produce one of the controlled phase instructions.

Parameters: angle – The input phase angle to apply when both qubits are in the ground state. q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.CPHASE01(*params)

Produces a CPHASE01 instruction. This gate applies to two qubit arguments to produce one of the controlled phase instructions.

Parameters: angle – The input phase angle to apply when q1 is in the excited state and q2 is in the ground state. q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.CPHASE10(*params)

Produces a CPHASE10 instruction. This gate applies to two qubit arguments to produce one of the controlled phase instructions.

Parameters: angle – The input phase angle to apply when q2 is in the excited state and q1 is in the ground state. q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.CSWAP(*qubits)

Produces a SWAP instruction. This gate swaps the state of two qubits.

Parameters: q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.EXCHANGE(classical_reg1, classical_reg2)[source]

Produce an EXCHANGE instruction.

Parameters: classical_reg1 – The first classical register, which gets modified. classical_reg2 – The second classical register, which gets modified. A ClassicalExchange instance.
pyquil.gates.FALSE(classical_reg)[source]

Produce a FALSE instruction.

Parameters: classical_reg – A classical register to modify. A ClassicalFalse instance.
pyquil.gates.H(*qubits)

Produces the H instruction. This gate is a single qubit Hadamard gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.HALT = <pyquil.quilbase.Halt object>

This instruction ends the program.

Returns: A Halt object.
pyquil.gates.I(*qubits)

Produces the I instruction. This gate is a single qubit identity gate. Note that this gate is different that the NOP instruction as noise channels are typically still applied during the duration of identity gates. Identities will also block parallelization like any other gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.ISWAP(*qubits)

Produces an ISWAP instruction. This gate swaps the state of two qubits, applying a -i phase to q1 when it is in the excited state and a -i phase to q2 when it is in the ground state.

Parameters: q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.MEASURE(qubit, classical_reg=None)[source]

Produce a MEASURE instruction.

Parameters: qubit – The qubit to measure. classical_reg – The classical register to measure into, or None. A Measurement instance.
pyquil.gates.MOVE(classical_reg1, classical_reg2)[source]

Produce a MOVE instruction.

Parameters: classical_reg1 – The first classical register. classical_reg2 – The second classical register, which gets modified. A ClassicalMove instance.
pyquil.gates.NOP = <pyquil.quilbase.Nop object>

This instruction applies no operation at that timestep. Typically these are ignored in error-models.

Returns: A Nop object.
pyquil.gates.NOT(classical_reg)[source]

Produce a NOT instruction.

Parameters: classical_reg – A classical register to modify. A ClassicalNot instance.
pyquil.gates.OR(classical_reg1, classical_reg2)[source]

Produce an OR instruction.

Parameters: classical_reg1 – The first classical register. classical_reg2 – The second classical register, which gets modified. A ClassicalOr instance.
pyquil.gates.PHASE(*params)

Produces a PHASE instruction. This is the same as the RZ gate.

Parameters: angle – The angle to rotate around the z-axis on the bloch sphere. qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.PSWAP(*params)

Produces a PSWAP instruction. This is a parameterized swap gate.

Parameters: 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. q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.RESET = <pyquil.quilbase.Reset object>

This instruction resets all the qubits to the ground state.

Returns: A Reset object.
pyquil.gates.RX(*params)

Produces the RX instruction. This gate is a single qubit X-rotation.

Parameters: angle – The angle to rotate around the x-axis on the bloch sphere. qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.RY(*params)

Produces the RY instruction. This gate is a single qubit Y-rotation.

Parameters: angle – The angle to rotate around the y-axis on the bloch sphere. qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.RZ(*params)

Produces the RZ instruction. This gate is a single qubit Z-rotation.

Parameters: angle – The angle to rotate around the z-axis on the bloch sphere. qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.S(*qubits)

Produces the S instruction. This gate is a single qubit S-gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.STANDARD_GATES = {'CPHASE': <function gate_function>, 'CPHASE00': <function gate_function>, 'PSWAP': <function gate_function>, 'ISWAP': <function ctor>, 'I': <function ctor>, 'H': <function ctor>, 'CCNOT': <function ctor>, 'CSWAP': <function ctor>, 'RX': <function gate_function>, 'RY': <function gate_function>, 'RZ': <function gate_function>, 'CPHASE01': <function gate_function>, 'CPHASE10': <function gate_function>, 'PHASE': <function gate_function>, 'S': <function ctor>, 'T': <function ctor>, 'Y': <function ctor>, 'X': <function ctor>, 'Z': <function ctor>, 'CNOT': <function ctor>, 'SWAP': <function ctor>}

Dictionary of standard gates. Keys are gate names, values are gate functions.

pyquil.gates.SWAP(*qubits)

Produces a SWAP instruction. This gate swaps the state of two qubits.

Parameters: q1 – Qubit 1. q2 – Qubit 2. A Gate object.
pyquil.gates.T(*qubits)

Produces the T instruction. This gate is a single qubit T-gate. It is the same as RZ(pi/4).

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.TRUE(classical_reg)[source]

Produce a TRUE instruction.

Parameters: classical_reg – A classical register to modify. A ClassicalTrue instance.
pyquil.gates.WAIT = <pyquil.quilbase.Wait object>

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.
pyquil.gates.X(*qubits)

Produces the X instruction. This gate is a single qubit X-gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.Y(*qubits)

Produces the Y instruction. This gate is a single qubit Y-gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.Z(*qubits)

Produces the Z instruction. This gate is a single qubit Z-gate.

Parameters: qubit – The qubit apply the gate to. A Gate object.
pyquil.gates.unpack_classical_reg(c)[source]

Get the address for a classical register.

Parameters: c – A list of length 1 or an int or an Addr. The address as an Addr.
pyquil.gates.unpack_qubit(qubit)[source]

Get a qubit from an object.

Parameters: qubit – An int or AbstractQubit. An AbstractQubit instance