pyquil.gates module

pyquil.gates.ADD(classical_reg: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], right: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int]) pyquil.quilbase.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: pyquil.quilatom.Frame, kernel: Union[pyquil.quilatom.WaveformReference, pyquil.quilatom.TemplateWaveform], memory_region: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], nonblocking: bool = False) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], control2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], control: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], control: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], control: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], control: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target_1: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target_2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], target: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Optional[str] = None, offsets: Optional[Iterable[Tuple[int, str]]] = None) pyquil.quilbase.Declare[source]
pyquil.gates.DELAY(*args) Union[pyquil.quilbase.DelayFrames, pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], right: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg3: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]) pyquil.quilbase.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: Union[int, pyquil.quilatom.Qubit, pyquil.quilatom.FormalArgument]) Union[pyquil.quilbase.FenceAll, pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg3: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg3: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Iterable[Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]], qubits: Iterable[Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument]])[source]

Bases: pyquil.quilbase.AbstractInstruction

This is the pyQuil object for a quantum gate instruction.

controlled(control_qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int, Sequence[Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]]]) pyquil.quilbase.Gate[source]

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

dagger() pyquil.quilbase.Gate[source]

Add the DAGGER modifier to the gate.

forked(fork_qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], alt_params: List[Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]]) pyquil.quilbase.Gate[source]

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

get_qubits(indices: bool = True) Set[Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]][source]
out() str[source]
pyquil.gates.H(qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], q2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg3: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], region_name: str, offset_reg: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg3: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], classical_reg: Optional[Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], right: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str]) pyquil.quilbase.ClassicalNot[source]

Produce a NOT instruction.

Parameters

classical_reg – A classical register to modify.

Returns

A ClassicalNot instance.

pyquil.gates.PHASE(angle: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], q1: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], q2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: pyquil.quilatom.Frame, waveform: Union[pyquil.quilatom.WaveformReference, pyquil.quilatom.TemplateWaveform], nonblocking: bool = False) pyquil.quilbase.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[[...], pyquil.quilbase.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[[...], pyquil.quilbase.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_PHASE>}

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

pyquil.gates.RAW_CAPTURE(frame: pyquil.quilatom.Frame, duration: float, memory_region: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], nonblocking: bool = False) pyquil.quilbase.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: Optional[Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]] = None) Union[pyquil.quilbase.Reset, pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: pyquil.quilatom.Frame, freq: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]) pyquil.quilbase.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: pyquil.quilatom.Frame, phase: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]) pyquil.quilbase.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: pyquil.quilatom.Frame, scale: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]) pyquil.quilbase.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: pyquil.quilatom.Frame, freq: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]) pyquil.quilbase.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: pyquil.quilatom.Frame, phase: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex]) pyquil.quilbase.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, Union[pyquil.quilbase.AbstractInstruction, Callable[[...], pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], source: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], right: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int, float]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], q2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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_PHASE(frameA: pyquil.quilatom.Frame, frameB: pyquil.quilatom.Frame) pyquil.quilbase.SwapPhase[source]

Produce a SWAP-PHASE instruction.

Parameters
  • frameA – A frame.

  • frameB – A frame.

Returns

A SwapPhase instance.

pyquil.gates.T(qubit: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str], classical_reg2: Union[pyquil.quilatom.MemoryReference, Tuple[str, int], List[Any], str, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Expression, pyquil.quilatom.MemoryReference, numpy.int64, int, float, complex], q1: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int], q2: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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: Union[pyquil.quilatom.Qubit, pyquil.quilatom.QubitPlaceholder, pyquil.quilatom.FormalArgument, int]) pyquil.quilbase.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.