pyquil.gates module

pyquil.gates.ADD(classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, right: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalAdd[source]

Produce an ADD instruction.

Parameters:
  • classical_reg – Left operand for the arithmetic operation. Also serves as the store target.

  • right – Right operand for the arithmetic operation.

Returns:

A ClassicalAdd instance.

pyquil.gates.AND(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int) ClassicalAnd[source]

Produce an AND instruction.

NOTE: The order of operands was reversed in pyQuil <=1.9 .

Parameters:
  • classical_reg1 – The first classical register, which gets modified.

  • classical_reg2 – The second classical register or immediate value.

Returns:

A ClassicalAnd instance.

pyquil.gates.CAPTURE(frame: Frame, kernel: WaveformReference | TemplateWaveform, memory_region: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, nonblocking: bool = False) Capture[source]

Produce a CAPTURE instruction.

Parameters:
  • frame – The frame on which to capture an IQ value.

  • kernel – The integrating kernel for the capture.

  • memory_region – The classical memory region to store the resulting IQ value.

  • nonblocking – A flag indicating whether the capture is NONBLOCKING.

Returns:

A Capture instance.

pyquil.gates.CCNOT(control1: Qubit | QubitPlaceholder | FormalArgument | int, control2: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a doubly-controlled NOT gate:

CCNOT = [[1, 0, 0, 0, 0, 0, 0, 0],
         [0, 1, 0, 0, 0, 0, 0, 0],
         [0, 0, 1, 0, 0, 0, 0, 0],
         [0, 0, 0, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 0, 0, 0],
         [0, 0, 0, 0, 0, 1, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 1],
         [0, 0, 0, 0, 0, 0, 1, 0]]

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

Parameters:
  • control1 – The first control qubit.

  • control2 – 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.

Returns:

A Gate object.

pyquil.gates.CNOT(control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-NOT (controlled-X) gate:

CNOT = [[1, 0, 0, 0],
        [0, 1, 0, 0],
        [0, 0, 0, 1],
        [0, 0, 1, 0]]

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 |1> state.

Returns:

A Gate object.

pyquil.gates.CONVERT(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str) ClassicalConvert[source]

Produce a CONVERT instruction.

Parameters:
  • classical_reg1 – MemoryReference to store to.

  • classical_reg2 – MemoryReference to read from.

Returns:

A ClassicalConvert instance.

pyquil.gates.CPHASE(angle: Expression | MemoryReference | int64 | int | float | complex, control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-phase instruction:

CPHASE(phi) = diag([1, 1, 1, exp(1j * phi)])

This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 11.

Compare with the CPHASExx variants. This variant is the most common and does not have a suffix, although you can think of it as CPHASE11.

Parameters:
  • angle – The input phase angle to apply when both qubits are in the |1> state.

  • control – Qubit 1.

  • target – Qubit 2.

Returns:

A Gate object.

pyquil.gates.CPHASE00(angle: Expression | MemoryReference | int | float | complex | number, control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-phase gate that phases the |00> state:

CPHASE00(phi) = diag([exp(1j * phi), 1, 1, 1])

This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 00.

Parameters:
  • angle – The input phase angle to apply when both qubits are in the |0> state.

  • control – Qubit 1.

  • target – Qubit 2.

Returns:

A Gate object.

pyquil.gates.CPHASE01(angle: Expression | MemoryReference | int | float | complex | number, control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-phase gate that phases the |01> state:

CPHASE01(phi) = diag([1.0, exp(1j * phi), 1.0, 1.0])

This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 01.

Parameters:
  • angle – The input phase angle to apply when q1 is in the |1> state and q2 is in the |0> state.

  • control – Qubit 1.

  • target – Qubit 2.

Returns:

A Gate object.

pyquil.gates.CPHASE10(angle: Expression | MemoryReference | int | float | complex | number, control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-phase gate that phases the |10> state:

CPHASE10(phi) = diag([1, 1, exp(1j * phi), 1])

This gate applies to two qubit arguments to produce the variant of the controlled phase instruction that affects the state 10.

Parameters:
  • angle – The input phase angle to apply when q2 is in the |1> state and q1 is in the |0> state.

  • control – Qubit 1.

  • target – Qubit 2.

Returns:

A Gate object.

pyquil.gates.CSWAP(control: Qubit | QubitPlaceholder | FormalArgument | int, target_1: Qubit | QubitPlaceholder | FormalArgument | int, target_2: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-SWAP gate. This gate conditionally swaps the state of two qubits:

CSWAP = [[1, 0, 0, 0, 0, 0, 0, 0],
         [0, 1, 0, 0, 0, 0, 0, 0],
         [0, 0, 1, 0, 0, 0, 0, 0],
         [0, 0, 0, 1, 0, 0, 0, 0],
         [0, 0, 0, 0, 1, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 1, 0],
         [0, 0, 0, 0, 0, 1, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 1]]
Parameters:
  • control – The control qubit.

  • target_1 – The first target qubit.

  • target_2 – The second target qubit. The two target states are swapped if the control is in the |1> state.

pyquil.gates.CZ(control: Qubit | QubitPlaceholder | FormalArgument | int, target: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a controlled-Z gate:

CZ = [[1, 0, 0,  0],
      [0, 1, 0,  0],
      [0, 0, 1,  0],
      [0, 0, 0, -1]]

This gate applies to two qubit arguments to produce the controlled-Z gate instruction.

Parameters:
  • control – The control qubit.

  • target – The target qubit. The target qubit has an Z-gate applied to it if the control qubit is in the excited state.

Returns:

A Gate object.

pyquil.gates.DECLARE(name: str, memory_type: str = 'BIT', memory_size: int = 1, shared_region: str | None = None, offsets: Sequence[Tuple[int, str]] | None = None) Declare[source]
pyquil.gates.DELAY(*args) DelayFrames | DelayQubits[source]

Produce a DELAY instruction.

Note: There are two variants of DELAY. One applies to specific frames on some qubit, e.g. DELAY 0 “rf” “ff” 1.0 delays the “rf” and “ff” frames on 0. It is also possible to delay all frames on some qubits, e.g. DELAY 0 1 2 1.0.

Parameters:

args – A list of delay targets, ending with a duration.

Returns:

A DelayFrames or DelayQubits instance.

pyquil.gates.DIV(classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, right: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalDiv[source]

Produce an DIV instruction.

Parameters:
  • classical_reg – Left operand for the arithmetic operation. Also serves as the store target.

  • right – Right operand for the arithmetic operation.

Returns:

A ClassicalDiv instance.

pyquil.gates.EQ(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg3: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalEqual[source]

Produce an EQ instruction.

Parameters:
  • classical_reg1 – Memory address to which to store the comparison result.

  • classical_reg2 – Left comparison operand.

  • classical_reg3 – Right comparison operand.

Returns:

A ClassicalEqual instance.

pyquil.gates.EXCHANGE(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str) ClassicalExchange[source]

Produce an EXCHANGE instruction.

Parameters:
  • classical_reg1 – The first classical register, which gets modified.

  • classical_reg2 – The second classical register, which gets modified.

Returns:

A ClassicalExchange instance.

pyquil.gates.FENCE(*qubits: int | Qubit | FormalArgument) FenceAll | Fence[source]

Produce a FENCE instruction.

Note: If no qubits are specified, then this is interpreted as a global FENCE.

Params qubits:

A list of qubits or formal arguments.

Returns:

A Fence or FenceAll instance.

pyquil.gates.GE(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg3: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalGreaterEqual[source]

Produce an GE instruction.

Parameters:
  • classical_reg1 – Memory address to which to store the comparison result.

  • classical_reg2 – Left comparison operand.

  • classical_reg3 – Right comparison operand.

Returns:

A ClassicalGreaterEqual instance.

pyquil.gates.GT(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg3: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalGreaterThan[source]

Produce an GT instruction.

Parameters:
  • classical_reg1 – Memory address to which to store the comparison result.

  • classical_reg2 – Left comparison operand.

  • classical_reg3 – Right comparison operand.

Returns:

A ClassicalGreaterThan instance.

class pyquil.gates.Gate(name: str, params: Sequence[Expression | MemoryReference | int | float | complex | number], qubits: Sequence[Qubit | QubitPlaceholder | FormalArgument | int], modifiers: Sequence[GateModifier] = [])[source]

Bases: Gate, AbstractInstruction

This is the pyQuil object for a quantum gate instruction.

controlled(control_qubit: Qubit | Qubit | QubitPlaceholder | FormalArgument | int | Sequence[Qubit | QubitPlaceholder | FormalArgument | int | Qubit]) Gate[source]

Add the CONTROLLED modifier to the gate with the given control qubit or Sequence of control qubits.

dagger() Gate[source]

Add the DAGGER modifier to the gate.

forked(fork_qubit: Qubit | Qubit | QubitPlaceholder | FormalArgument | int, alt_params: Sequence[Expression | MemoryReference | int | float | complex | number] | Sequence[Expression]) Gate[source]

Add the FORKED modifier to the gate with the given fork qubit and given additional parameters.

get_qubit_indices() List[int][source]
get_qubits(indices: bool = True) Sequence[Qubit | QubitPlaceholder | FormalArgument | int][source]

Deprecated since version 4.0: The indices flag will be removed, use get_qubit_indices() instead.

property modifiers: List[str]
out() str[source]
property params: Sequence[Expression | MemoryReference | int | float | complex | number]
property qubits: List[Qubit | QubitPlaceholder | FormalArgument | int]
pyquil.gates.H(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the Hadamard gate:

H = (1 / sqrt(2)) * [[1,  1],
                     [1, -1]]

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

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.

pyquil.gates.HALT = <pyquil.quilbase.Halt object>

This instruction ends the program.

Returns:

A Halt object.

pyquil.gates.I(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the I identity gate:

I = [1, 0]
    [0, 1]

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.

Returns:

A Gate object.

pyquil.gates.IOR(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int) ClassicalInclusiveOr[source]

Produce an inclusive OR instruction.

Parameters:
  • classical_reg1 – The first classical register, which gets modified.

  • classical_reg2 – The second classical register or immediate value.

Returns:

A ClassicalInclusiveOr instance.

pyquil.gates.ISWAP(q1: Qubit | QubitPlaceholder | FormalArgument | int, q2: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces an ISWAP gate:

ISWAP = [[1, 0,  0,  0],
         [0, 0,  1j, 0],
         [0, 1j, 0,  0],
         [0, 0,  0,  1]]

This gate swaps the state of two qubits, applying a -i phase to q1 when it is in the 1 state and a -i phase to q2 when it is in the 0 state.

Parameters:
  • q1 – Qubit 1.

  • q2 – Qubit 2.

Returns:

A Gate object.

pyquil.gates.LE(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg3: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalLessEqual[source]

Produce an LE instruction.

Parameters:
  • classical_reg1 – Memory address to which to store the comparison result.

  • classical_reg2 – Left comparison operand.

  • classical_reg3 – Right comparison operand.

Returns:

A ClassicalLessEqual instance.

pyquil.gates.LOAD(target_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, region_name: str, offset_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str) ClassicalLoad[source]

Produce a LOAD instruction.

Parameters:
  • target_reg – LOAD storage target.

  • region_name – Named region of memory to load from.

  • offset_reg – Offset into region of memory to load from. Must be a MemoryReference.

Returns:

A ClassicalLoad instance.

pyquil.gates.LT(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg3: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalLessThan[source]

Produce an LT instruction.

Parameters:
  • classical_reg1 – Memory address to which to store the comparison result.

  • classical_reg2 – Left comparison operand.

  • classical_reg3 – Right comparison operand.

Returns:

A ClassicalLessThan instance.

pyquil.gates.MEASURE(qubit: Qubit | QubitPlaceholder | FormalArgument | int, classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | None) Measurement[source]

Produce a MEASURE instruction.

Parameters:
  • qubit – The qubit to measure.

  • classical_reg – The classical register to measure into, or None.

Returns:

A Measurement instance.

pyquil.gates.MOVE(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalMove[source]

Produce a MOVE instruction.

Parameters:
  • classical_reg1 – The first classical register, which gets modified.

  • classical_reg2 – The second classical register or immediate value.

Returns:

A ClassicalMove instance.

pyquil.gates.MUL(classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, right: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalMul[source]

Produce a MUL instruction.

Parameters:
  • classical_reg – Left operand for the arithmetic operation. Also serves as the store target.

  • right – Right operand for the arithmetic operation.

Returns:

A ClassicalMul instance.

pyquil.gates.NEG(classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str) ClassicalNeg[source]

Produce a NEG instruction.

Parameters:

classical_reg – A classical memory address to modify.

Returns:

A ClassicalNeg 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: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str) ClassicalNot[source]

Produce a NOT instruction.

Parameters:

classical_reg – A classical register to modify.

Returns:

A ClassicalNot instance.

pyquil.gates.PHASE(angle: Expression | MemoryReference | int | float | complex | number, qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the PHASE gate:

PHASE(phi) = [[1, 0],
              [0, exp(1j * phi)]]

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.

Returns:

A Gate object.

pyquil.gates.PSWAP(angle: Expression | MemoryReference | int | float | complex | number, q1: Qubit | QubitPlaceholder | FormalArgument | int, q2: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a parameterized SWAP gate:

PSWAP(phi) = [[1, 0,             0,             0],
              [0, 0,             exp(1j * phi), 0],
              [0, exp(1j * phi), 0,             0],
              [0, 0,             0,             1]]
Parameters:
  • angle – The angle of the phase to apply to the swapped states. This phase is applied to q1 when it is in the 1 state and to q2 when it is in the 0 state.

  • q1 – Qubit 1.

  • q2 – Qubit 2.

Returns:

A Gate object.

pyquil.gates.PULSE(frame: Frame, waveform: WaveformReference | TemplateWaveform, nonblocking: bool = False) Pulse[source]

Produce a PULSE instruction.

Parameters:
  • frame – The frame on which to apply the pulse.

  • waveform – The pulse waveform.

  • nonblocking – A flag indicating whether the pulse is NONBLOCKING.

Returns:

A Pulse instance.

pyquil.gates.QUANTUM_GATES: Mapping[str, Callable[[...], Gate]] = {'CCNOT': <function CCNOT>, 'CNOT': <function CNOT>, 'CPHASE': <function CPHASE>, 'CPHASE00': <function CPHASE00>, 'CPHASE01': <function CPHASE01>, 'CPHASE10': <function CPHASE10>, 'CSWAP': <function CSWAP>, 'CZ': <function CZ>, 'H': <function H>, 'I': <function I>, 'ISWAP': <function ISWAP>, 'PHASE': <function PHASE>, 'PSWAP': <function PSWAP>, 'RX': <function RX>, 'RY': <function RY>, 'RZ': <function RZ>, 'S': <function S>, 'SWAP': <function SWAP>, 'T': <function T>, 'X': <function X>, 'XY': <function XY>, 'Y': <function Y>, 'Z': <function Z>}

Dictionary of quantum gate functions keyed by gate names.

pyquil.gates.QUILT_INSTRUCTIONS: Mapping[str, Callable[[...], AbstractInstruction]] = {'CAPTURE': <function CAPTURE>, 'DELAY': <function DELAY>, 'FENCE': <function FENCE>, 'PULSE': <function PULSE>, 'RAW-CAPTURE': <function RAW_CAPTURE>, 'SET-FREQUENCY': <function SET_FREQUENCY>, 'SET-PHASE': <function SET_PHASE>, 'SET-SCALE': <function SET_SCALE>, 'SHIFT-FREQUENCY': <function SHIFT_FREQUENCY>, 'SHIFT-PHASE': <function SHIFT_PHASE>, 'SWAP-PHASE': <function SWAP_PHASES>, 'SWAP-PHASES': <function SWAP_PHASES>}

Dictionary of Quil-T AST construction functions keyed by instruction name.

pyquil.gates.RAW_CAPTURE(frame: Frame, duration: float, memory_region: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, nonblocking: bool = False) RawCapture[source]

Produce a RAW-CAPTURE instruction.

Parameters:
  • frame – The frame on which to capture raw values.

  • duration – The duration of the capture, in seconds.

  • memory_region – The classical memory region to store the resulting raw values.

  • nonblocking – A flag indicating whether the capture is NONBLOCKING.

Returns:

A RawCapture instance.

pyquil.gates.RESET(qubit_index: Qubit | QubitPlaceholder | FormalArgument | int | None = None) Reset | ResetQubit[source]

Reset all qubits or just one specific qubit.

Parameters:

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.

pyquil.gates.RX(angle: Expression | MemoryReference | int | float | complex | number, qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the RX gate:

RX(phi) = [[cos(phi / 2), -1j * sin(phi / 2)],
           [-1j * sin(phi / 2), cos(phi / 2)]]

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.

Returns:

A Gate object.

pyquil.gates.RY(angle: Expression | MemoryReference | int | float | complex | number, qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the RY gate:

RY(phi) = [[cos(phi / 2), -sin(phi / 2)],
           [sin(phi / 2), cos(phi / 2)]]

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.

Returns:

A Gate object.

pyquil.gates.RZ(angle: Expression | MemoryReference | int | float | complex | number, qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the RZ gate:

RZ(phi) = [[cos(phi / 2) - 1j * sin(phi / 2), 0]
           [0, cos(phi / 2) + 1j * sin(phi / 2)]]

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.

Returns:

A Gate object.

pyquil.gates.S(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the S gate:

S = [[1, 0],
     [0, 1j]]

This gate is a single qubit S-gate.

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.

pyquil.gates.SET_FREQUENCY(frame: Frame, freq: Expression | MemoryReference | int | float | complex | number) SetFrequency[source]

Produce a SET-FREQUENCY instruction.

Parameters:
  • frame – The frame on which to set the frequency.

  • freq – The frequency value, in Hz.

Returns:

A SetFrequency instance.

pyquil.gates.SET_PHASE(frame: Frame, phase: Expression | MemoryReference | int | float | complex | number) SetPhase[source]

Produce a SET-PHASE instruction.

Parameters:
  • frame – The frame on which to set the phase.

  • phase – The new phase value, in radians.

Returns:

A SetPhase instance.

pyquil.gates.SET_SCALE(frame: Frame, scale: Expression | MemoryReference | int | float | complex | number) SetScale[source]

Produce a SET-SCALE instruction.

Parameters:
  • frame – The frame on which to set the scale.

  • scale – The scaling factor.

Returns:

A SetScale instance.

pyquil.gates.SHIFT_FREQUENCY(frame: Frame, freq: Expression | MemoryReference | int | float | complex | number) ShiftFrequency[source]

Produce a SHIFT-FREQUENCY instruction.

Parameters:
  • frame – The frame on which to shift the frequency.

  • freq – The value, in Hz, to add to the existing frequency.

Returns:

A ShiftFrequency instance.

pyquil.gates.SHIFT_PHASE(frame: Frame, phase: Expression | MemoryReference | int | float | complex | number) ShiftPhase[source]

Produce a SHIFT-PHASE instruction.

Parameters:
  • frame – The frame on which to shift the phase.

  • phase – The value, in radians, to add to the existing phase.

Returns:

A ShiftPhase instance.

pyquil.gates.STANDARD_GATES = {'CCNOT': <function CCNOT>, 'CNOT': <function CNOT>, 'CPHASE': <function CPHASE>, 'CPHASE00': <function CPHASE00>, 'CPHASE01': <function CPHASE01>, 'CPHASE10': <function CPHASE10>, 'CSWAP': <function CSWAP>, 'CZ': <function CZ>, 'H': <function H>, 'I': <function I>, 'ISWAP': <function ISWAP>, 'PHASE': <function PHASE>, 'PSWAP': <function PSWAP>, 'RX': <function RX>, 'RY': <function RY>, 'RZ': <function RZ>, 'S': <function S>, 'SWAP': <function SWAP>, 'T': <function T>, 'X': <function X>, 'XY': <function XY>, 'Y': <function Y>, 'Z': <function Z>}

Alias for the above dictionary of quantum gates.

pyquil.gates.STANDARD_INSTRUCTIONS: Mapping[str, AbstractInstruction | Callable[[...], AbstractInstruction]] = {'ADD': <function ADD>, 'AND': <function AND>, 'CONVERT': <function CONVERT>, 'DECLARE': <function DECLARE>, 'DIV': <function DIV>, 'EQ': <function EQ>, 'EXCHANGE': <function EXCHANGE>, 'GE': <function GE>, 'GT': <function GT>, 'HALT': <pyquil.quilbase.Halt object>, 'IOR': <function IOR>, 'LE': <function LE>, 'LOAD': <function LOAD>, 'LT': <function LT>, 'MEASURE': <function MEASURE>, 'MOVE': <function MOVE>, 'MUL': <function MUL>, 'NEG': <function NEG>, 'NOP': <pyquil.quilbase.Nop object>, 'NOT': <function NOT>, 'RESET': <function RESET>, 'STORE': <function STORE>, 'SUB': <function SUB>, 'WAIT': <pyquil.quilbase.Wait object>, 'XOR': <function XOR>}

Dictionary of standard instruction functions keyed by instruction names.

pyquil.gates.STORE(region_name: str, offset_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, source: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalStore[source]

Produce a STORE instruction.

Parameters:
  • region_name – Named region of memory to store to.

  • offset_reg – Offset into memory region. Must be a MemoryReference.

  • source – Source data. Can be either a MemoryReference or a constant.

Returns:

A ClassicalStore instance.

pyquil.gates.SUB(classical_reg: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, right: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int | float) ClassicalSub[source]

Produce a SUB instruction.

Parameters:
  • classical_reg – Left operand for the arithmetic operation. Also serves as the store target.

  • right – Right operand for the arithmetic operation.

Returns:

A ClassicalSub instance.

pyquil.gates.SWAP(q1: Qubit | QubitPlaceholder | FormalArgument | int, q2: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a SWAP gate which swaps the state of two qubits:

SWAP = [[1, 0, 0, 0],
        [0, 0, 1, 0],
        [0, 1, 0, 0],
        [0, 0, 0, 1]]
Parameters:
  • q1 – Qubit 1.

  • q2 – Qubit 2.

Returns:

A Gate object.

pyquil.gates.SWAP_PHASES(frameA: Frame, frameB: Frame) SwapPhases[source]

Produce a SWAP-PHASES instruction.

Parameters:
  • frameA – A frame.

  • frameB – A frame.

Returns:

A SwapPhases instance.

New in version 3.5.1: The correct instruction is SWAP-PHASES, not SWAP-PHASE

pyquil.gates.T(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the T gate:

T = [[1, 0],
     [0, exp(1j * pi / 4)]]

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

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.

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(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the X (“NOT”) gate:

X = [[0, 1],
     [1, 0]]

This gate is a single qubit X-gate.

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.

pyquil.gates.XOR(classical_reg1: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str, classical_reg2: MemoryReference | MemoryReference | Tuple[str, int] | List[Any] | str | int) ClassicalExclusiveOr[source]

Produce an exclusive OR instruction.

Parameters:
  • classical_reg1 – The first classical register, which gets modified.

  • classical_reg2 – The second classical register or immediate value.

Returns:

A ClassicalExclusiveOr instance.

pyquil.gates.XY(angle: Expression | MemoryReference | int | float | complex | number, q1: Qubit | QubitPlaceholder | FormalArgument | int, q2: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces a parameterized ISWAP gate:

XY(phi) = [[1,               0,               0, 0],
           [0,      cos(phi/2), 1j * sin(phi/2), 0],
           [0, 1j * sin(phi/2),      cos(phi/2), 0],
           [0,               0,               0, 1]]
Parameters:
  • angle – The angle of the rotation to apply to the population 1 subspace.

  • q1 – Qubit 1.

  • q2 – Qubit 2.

Returns:

A Gate object.

pyquil.gates.Y(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the Y gate:

Y = [[0, 0 - 1j],
     [0 + 1j, 0]]

This gate is a single qubit Y-gate.

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.

pyquil.gates.Z(qubit: Qubit | QubitPlaceholder | FormalArgument | int) Gate[source]

Produces the Z gate:

Z = [[1,  0],
     [0, -1]]

This gate is a single qubit Z-gate.

Parameters:

qubit – The qubit apply the gate to.

Returns:

A Gate object.