Qubit Operations#

API for gates and measurements.

Because the transpiler used by both the compiler and the simulator is implemented using Qiskit, all QuantumCircuit gates are supported.

The examples below illustrate operations.

Examples

This example uses the operations API to add gates and measurements to a procedure.

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cx, h, measure

@qcdl()
def operations_api(q0, q1):
    h(q0)
    cx(q0, q1)
    measure(q0)
    measure(q1)

qcdl_program = operations_api()

This example is equivalent to the above example.

from dwave.gate.qcdl import qcdl

@qcdl()
def qcdl_module_methods(q0, q1):
    q0.h()
    q0.cx(q1)
    q0.measure()
    q1.measure()

qcdl_program = qcdl_module_methods()
barrier(*qubits: QCDLModule, label: str | None = None) → None[source]#

Place a barrier on qubits.

The transpiler does not combine gates across a barrier. This is a directive to the transpiler and for dynamical decoupling, and is otherwise handled like a comment.

Note

This operation is different from a sync() method, which is used to control the order that the compiler schedules operations.

Parameters:
  • *qubits (QCDLModule) – The qubits to put a barrier on.

  • label (str, optional) – An annotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.utils.display import print_qcdl
from dwave.gate.qcdl.operations import barrier, measure, x

@qcdl()
def use_barrier(q0):
    x(q0)
    barrier(q0, label="Separate two X gates")
    x(q0)
    measure(q0)

qcdl_program = use_barrier()
print_qcdl(qcdl_program)

The code above prints the following QCDL.

begin quantum
    x([q0], q0)
    q0.barrier(label="Separate two X gates")
    x([q0], q0)
    measure([q0], q0, log=True)
end quantum
cp(control_qubit: QCDLModule, target_qubit: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Controlled-Phase gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

  • theta – \(\theta\) angle of the rotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cp, h, measure

@qcdl(2)
def cp_gate(q0, q1):
    h(q0)
    cp(control_qubit=q0, target_qubit=q1, theta=0.1)
    measure(q1)

qcdl_program = cp_gate()
crx(control_qubit: QCDLModule, target_qubit: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Controlled-RX gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

  • theta – \(\theta\) angle of the rotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import crx, h, measure

@qcdl(2)
def crx_gate(q0, q1):
    h(q0)
    crx(control_qubit=q0, target_qubit=q1, theta=0.1)
    measure(q1)

qcdl_program = crx_gate()
cry(control_qubit: QCDLModule, target_qubit: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Controlled-RY gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

  • theta – \(\theta\) angle of the rotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cry, h, measure

@qcdl(2)
def cry_gate(q0, q1):
    h(q0)
    cry(control_qubit=q0, target_qubit=q1, theta=0.1)
    measure(q1)

qcdl_program = cry_gate()
crz(control_qubit: QCDLModule, target_qubit: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Controlled-RZ gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

  • theta – \(\theta\) angle of the rotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import crz, h, measure

@qcdl(2)
def crz_gate(q0, q1):
    h(q0)
    crz(control_qubit=q0, target_qubit=q1, theta=0.1)
    measure(q1)

qcdl_program = crz_gate()
cu(control_qubit: QCDLModule, target_qubit: QCDLModule, theta: float | FixedPointRegister, phi: float | FixedPointRegister, lam: float | FixedPointRegister, gamma: float | FixedPointRegister) → None[source]#

Controlled-U gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

  • theta – \(\theta\) angle of rotation.

  • phi – \(\phi\) angle of rotation.

  • lam – \(\lambda\) angle of rotation.

  • gamma – Global phase of the gate, if applicable.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cu, h, measure

@qcdl(2)
def cu_gate(q0, q1):
    h(q0)
    cu(
        control_qubit=q0, target_qubit=q1,
        theta=0.1, phi=0.2, lam=0.3, gamma=-0.1
    )
    measure(q1)

qcdl_program = cu_gate()
cx(control_qubit: QCDLModule, target_qubit: QCDLModule) → None[source]#

Controlled-X gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cx, h, measure

@qcdl(2)
def cx_gate(q0, q1):
    h(q0)
    cx(control_qubit=q0, target_qubit=q1)
    measure(q1)

qcdl_program = cx_gate()
cy(control_qubit: QCDLModule, target_qubit: QCDLModule) → None[source]#

Controlled-Y gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cy, h, measure

@qcdl(2)
def cy_gate(q0, q1):
    h(q0)
    cy(control_qubit=q0, target_qubit=q1)
    measure(q1)

qcdl_program = cy_gate()
cz(control_qubit: QCDLModule, target_qubit: QCDLModule) → None[source]#

Controlled-Z gate.

Parameters:
  • control_qubit – Control qubit.

  • target_qubit – Targeted qubit.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import cz, h, measure

@qcdl(2)
def cz_gate(q0, q1):
    h(q0)
    cz(control_qubit=q0, target_qubit=q1)
    measure(q1)

qcdl_program = cz_gate()
h(qubit: QCDLModule) → None[source]#

Hadamard gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure

@qcdl(1)
def h_gate(q0):
    h(q0)
    measure(q0)

qcdl_program = h_gate()
initialize(*qubits: QCDLModule) → None[source]#

Initialize qubits.

This function has non-deterministic duration because the implementation is to loop until all qubits are reset. This means that currently all qubits in the program must be included in the call.

Note

This function is implicitly added by default at the beginning of all programs.

Parameters:

*qubits (QCDLModule) – Qubits to initialize. It is not an error to do so, but unused qubits should not be included.

mced(qubit: QCDLModule, register: Register, mirror: bool = True) → None[source]#

Perform a non-destructive mid-circuit erasure detection (MCED).

Parameters:
  • qubit (QCDLModule) – The qubit to inspect.

  • register (Register) –

    Register used for storing the outcome. Supported outcomes are:

    • 0: No erasure detected

    • 1: Erasure detected.

  • mirror (bool) – If True and if using a register, mirrors the outcome to all qubits in the register. If False, the register is updated only for the selected qubit. Mirroring may be skipped or deferred because it can be expensive.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, mced, measure, rx

@qcdl(1)
def mced_use(q0):
    r0 = q0.Register()
    h(q0)
    mced(q0, register=r0)
    rx(q0, phi=0.1)
    measure(q0)

qcdl_program = mced_use()
measure(qubit: QCDLModule, log: bool = True, tag: str | None = None, register: Register | None = None, mirror: bool = True) → None[source]#

Measure a qubit.

Parameters:
  • qubit (QCDLModule) – The qubit to measure.

  • log (bool, optional) – If True, the measurement result is logged, meaning it is included in the returned array for this qubit.

  • tag (str | None, optional) – Name for this measurement, used to organize the results. Tagging is not compatible with programs that do not generate the same number of measurements per shot, which requires real-time measurements.

  • register (Register | None, optional) – Register for storing the outcome. Supported values are \(0\), \(1\), or \(-1\) (for splat). (See the LogicalOutcomeToInteger class.)

  • mirror (bool) – If True and if using a register, mirrors the outcome to all qubits in the register. If False, the register is updated only for the selected qubit. Mirroring may be skipped or deferred because it can be expensive.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure

@qcdl(1)
def measurement(q0):
    r0 = q0.Register(name="r0")
    h(q0)
    measure(q0, tag="my measurement", register=r0)

qcdl_program = measurement()
p(qubit: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Phase gate.

Parameters:
  • qubit – Qubit on which to apply the gate.

  • phi – \(\theta\) angle of rotation about the Z axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, p

@qcdl(1)
def p_gate(q0):
    h(q0)
    p(q0, theta=0.1)
    measure(q0)

qcdl_program = p_gate()
rx(qubit: QCDLModule, phi: float | FixedPointRegister) → None[source]#

Single-qubit X-axis rotation gate.

Parameters:
  • qubit – Qubit on which to apply the gate.

  • phi – \(\phi\) angle of rotation about the X axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, rx

@qcdl(1)
def rx_gate(q0):
    h(q0)
    rx(q0, phi=0.1)
    measure(q0)

qcdl_program = rx_gate()
rxx(qubit1: QCDLModule, qubit2: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Two-qubit XX-axis rotation gate.

Parameters:
  • qubit1 – A qubit on which to apply the gate.

  • qubit2 – A qubit on which to apply the gate.

  • theta – \(\theta\) angle of rotation about the XX axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, rxx

@qcdl(2)
def rxx_gate(q0, q1):
    h(q0)
    rxx(q0, q1, theta=0.1)
    measure(q0)

qcdl_program = rxx_gate()
ry(qubit: QCDLModule, phi: float | FixedPointRegister) → None[source]#

Single-qubit Y-axis rotation gate.

Parameters:
  • qubit – Qubit on which to apply the gate.

  • phi – \(\phi\) angle of rotation about the Y axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, ry

@qcdl(1)
def ry_gate(q0):
    h(q0)
    ry(q0, phi=0.1)
    measure(q0)

qcdl_program = ry_gate()
ryy(qubit1: QCDLModule, qubit2: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Two-qubit YY-axis rotation gate.

Parameters:
  • qubit1 – A qubit on which to apply the gate.

  • qubit2 – A qubit on which to apply the gate.

  • theta – \(\theta\) angle of rotation about the YY axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, ryy

@qcdl(2)
def ryy_gate(q0, q1):
    h(q0)
    ryy(q0, q1, theta=0.1)
    measure(q0)

qcdl_program = ryy_gate()
rz(qubit: QCDLModule, phi: float | FixedPointRegister) → None[source]#

Single-qubit Z-axis rotation gate.

Parameters:
  • qubit – Qubit on which to apply the gate.

  • phi – \(\phi\) angle of rotation about the Z axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, rz

@qcdl(1)
def rz_gate(q0):
    h(q0)
    rz(q0, phi=0.1)
    measure(q0)

qcdl_program = rz_gate()
rzz(qubit1: QCDLModule, qubit2: QCDLModule, theta: float | FixedPointRegister) → None[source]#

Two-qubit ZZ-axis rotation gate.

Parameters:
  • qubit1 – A qubit on which to apply the gate.

  • qubit2 – A qubit on which to apply the gate.

  • theta – \(\theta\) angle of rotation about the ZZ axis.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, rzz

@qcdl(2)
def rzz_gate(q0, q1):
    h(q0)
    rzz(q0, q1, theta=0.1)
    measure(q0)

qcdl_program = rzz_gate()
s(qubit: QCDLModule) → None[source]#

S gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, s

@qcdl(1)
def s_gate(q0):
    s(q0)
    measure(q0)

qcdl_program = s_gate()
sdg(qubit: QCDLModule) → None[source]#

S-adjoint (\(S^\dagger\)) gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, sdg

@qcdl(1)
def sdg_gate(q0):
    sdg(q0)
    measure(q0)

qcdl_program = sdg_gate()
swap(qubit1: QCDLModule, qubit2: QCDLModule) → None[source]#

Swap gate.

Swaps quantum states between qubit1 and qubit2.

Parameters:
  • qubit1 – A qubit.

  • qubit2 – A qubit.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import h, measure, swap

@qcdl(2)
def swap_gate(q0, q1):
    h(q0)
    swap(q0, q1)
    measure(q1)

qcdl_program = swap_gate()
sx(qubit: QCDLModule) → None[source]#

Square-root of X (\(\sqrt X\)) gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, sx

@qcdl(1)
def sx_gate(q0):
    sx(q0)
    measure(q0)

qcdl_program = sx_gate()
sy(qubit: QCDLModule) → None[source]#

SQRT of Y gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, sy

@qcdl(1)
def sy_gate(q0):
    sy(q0)
    measure(q0)

qcdl_program = sy_gate()
sydg(qubit: QCDLModule) → None[source]#

SQRT of Y_adjoint gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, sydg

@qcdl(1)
def sydg_gate(q0):
    sydg(q0)
    measure(q0)

qcdl_program = sydg_gate()
t(qubit: QCDLModule) → None[source]#

T (\(\sqrt[4]{Z}\)) gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, t

@qcdl(1)
def t_gate(q0):
    t(q0)
    measure(q0)

qcdl_program = t_gate()
tdg(qubit: QCDLModule) → None[source]#

T-adjoint (\(T^\dagger\)) gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, tdg

@qcdl(1)
def tdg_gate(q0):
    tdg(q0)
    measure(q0)

qcdl_program = tdg_gate()
u(qubit: QCDLModule, theta: float | FixedPointRegister, phi: float | FixedPointRegister, lam: float | FixedPointRegister) → None[source]#

Single-qubit generic U gate.

Parameters:
  • qubit – Qubit on which to apply the gate.

  • theta – \(\theta\) angle of rotation.

  • phi – \(\phi\) angle of rotation.

  • lam – \(\lambda\) angle of rotation.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, u

@qcdl(1)
def u_gate(q0):
    u(q0, theta=0.1, phi=0.2, lam=0.3)
    measure(q0)

qcdl_program = u_gate()
x(qubit: QCDLModule) → None[source]#

X gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, x

@qcdl(1)
def x_gate(q0):
    x(q0)
    measure(q0)

qcdl_program = x_gate()
y(qubit: QCDLModule) → None[source]#

Y gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, y

@qcdl(1)
def y_gate(q0):
    y(q0)
    measure(q0)

qcdl_program = y_gate()
z(qubit: QCDLModule) → None[source]#

Z gate.

Parameters:

qubit – Qubit on which to apply the gate.

Examples

from dwave.gate.qcdl import qcdl
from dwave.gate.qcdl.operations import measure, z

@qcdl(1)
def z_gate(q0):
    z(q0)
    measure(q0)

qcdl_program = z_gate()