hybridlane

hybridlane is a library for programming CV-DV quantum circuits with PennyLane.

Attributes

AJC

Anti-Jaynes-Cummings gate

CBS

Qubit-conditioned beamsplitter \(CBS(\theta, \varphi)\)

CD

Conditional displacement (CD) gate

CP

Conditional parity (CP) gate

CR

Conditional rotation (CR) gate

CS

Conditional squeezing (CS) gate

CSUM

Qubit-conditioned two-mode sum gate \(CSUM(\lambda)\)

CTMS

Qubit-conditioned two-mode squeezing \(CTMS(\xi)\)

ECD

Echoed-conditional displacement (ECD) gate

JC

Jaynes-Cummings gate

SQR

number-Selective Qubit Rotation (SQR) gate`

XCD

X-Conditional displacement (xCD) gate

YCD

Y-Conditional displacement (yCD) gate

Blue

Blue sideband gate

Red

Red sideband gate

BS

Beamsplitter gate \(BS(\theta, \varphi)\)

SNAP

Selective Number-dependent Arbitrary Phase (SNAP) gate

SUM

Two-mode summing gate \(SUM(\lambda)\)

TMS

Phase space two-mode squeezing \(TMS(r, \varphi)\)

A

Annihilation operator \(a\)

Ad

Creation operator \(\ad\)

C

Cubic phase shift gate \(C(r)\)

D

Phase space displacement gate \(D(\alpha)\)

F

Fourier gate

K

Kerr gate \(K(\kappa)\)

N

Number operator \(\hat{n}\)

P

Momentum operator \(\hat{p}\)

R

Phase space rotation gate \(R(\theta)\)

S

Phase space squeezing gate \(S(\zeta)\)

X

Position operator \(\hat{x}\)

qubits

Create a dictionary of qubit registers.

qumodes

Create a dictionary of qumode registers.

__version__

Classes

Hybrid

Mixin for hybrid CV-DV gates

FockRepresentation

Mixin for operators that define their representation in the Fock basis

QubitConditioned

Symbolic operator denoting a qubit-conditioned operator

AntiJaynesCummings

Anti-Jaynes-cummings gate \(AJC(\theta, \varphi)\), also known as Blue-Sideband

ConditionalBeamsplitter

Qubit-conditioned beamsplitter \(CBS(\theta, \varphi)\)

ConditionalDisplacement

Symmetric conditional displacement gate \(CD(\alpha)\)

ConditionalParity

Qubit-conditioned number parity gate \(CP\)

ConditionalRotation

Qubit-conditioned phase-space rotation \(CR(\theta)\)

ConditionalSqueezing

Qubit-conditioned squeezing gate \(CS(\zeta)\)

ConditionalTwoModeSqueezing

Qubit-conditioned two-mode squeezing \(CTMS(\xi)\)

ConditionalTwoModeSum

Qubit-conditioned two-mode sum gate \(CSUM(\lambda)\)

ConditionalXDisplacement

X-Conditional displacement gate \(xCD(\alpha)\)

ConditionalYDisplacement

Y-Conditional displacement gate \(yCD(\alpha)\)

EchoedConditionalDisplacement

Echoed conditional displacement gate \(ECD(\alpha)\)

JaynesCummings

Jaynes-cummings gate \(JC(\theta, \varphi)\), also known as Red-Sideband

Rabi

Rabi interaction \(RB(\theta)\)

SelectiveQubitRotation

number-Selective Qubit Rotation (SQR) gate \(SQR(\theta, \varphi, n)\)

AnnihilationOp

Continuous-variable annihilation operator \(a\)

Beamsplitter

Beamsplitter gate \(BS(\theta, \varphi)\)

CreationOp

Continuous-variable creation operator \(\ad\)

CubicPhase

Cubic phase shift gate \(C(r)\)

Displacement

Phase space displacement gate \(D(\alpha)\)

FockStateProjector

The projector onto a multi-mode Fock state

Fourier

Continuous-variable Fourier gate \(F\)

Kerr

Kerr gate \(K(\kappa)\)

ModeSwap

Continuous-variable SWAP between two qumodes

NumberOperator

Number operator \(\hat{n}\)

QuadOperator

The generalized quadrature observable \(\hat{x}_\phi\)

QuadP

Momentum operator \(\hat{p}\)

QuadX

Position operator \(\hat{x}\)

Rotation

Phase space rotation gate \(R(\theta)\)

SelectiveNumberArbitraryPhase

Selective Number-dependent Arbitrary Phase (SNAP) gate \(SNAP(\varphi, n)\)

Squeezing

Phase space squeezing gate \(S(r, \theta)\)

TwoModeSqueezing

Phase space two-mode squeezing \(TMS(r, \varphi)\)

TwoModeSum

Two-mode summing gate \(SUM(\lambda)\)

FockState

Prepares a definite Fock state from the vacuum

GKPState

GKP-state preparation on a qumode using non-Abelian QSP

SqueezedCatState

Cat-state preparation on a qumode using non-Abelian QSP

Qubit

Type representing a qubit

Qudit

Type representing a qudit with specified dimension

Qumode

Type representing a qumode

Functions

draw_mpl(qnode[, wire_order, show_all_wires, ...])

Draws a circuit using matplotlib

to_openqasm(qnode[, rotations, precision, strict, ...])

Converts a circuit to an OpenQASM 3.0 program

density_matrix([wires])

Density matrix measurement

expval(op)

Expectation value of the supplied observable

var(op)

Variance of the supplied observable

qcond(op, control_wires)

Creates a qubit-conditioned operator

Package Contents

hybridlane.draw_mpl(qnode, wire_order=None, show_all_wires=False, show_wire_types=True, decimals=None, style=None, *, max_length=None, fig=None, level='gradient', **kwargs)[source]

Draws a circuit using matplotlib

Parameters:
  • qnode (QNode | Callable) – The circuit to be drawn

  • wire_order (Sequence | None) – The display order (top to bottom) of wires in the circuit

  • show_all_wires (bool) – Whether to show all wires or just those that are used

  • show_wire_types (bool) – Whether to draw qubit/qumode icons next to each wire label

  • decimals (int | None) – The number of decimals to print circuit parameters with. If not provided, parameters won’t be shown.

  • style (str | None) – The drawing style to use. See qp.draw_mpl.

  • max_length (int | None)

  • level (Literal['top', 'user', 'device', 'gradient'] | int | slice)

Keyword Arguments:

wire_icon_colors (dict) – A dictionary mapping wires to optional matplotlib-compatible colors. All wires that aren’t provided will use default qubit or qumode colors.

For other arguments, see qp.draw_mpl.

Returns:

A function that when called, produces the same output as qp.draw_mpl

Parameters:
  • qnode (QNode | Callable)

  • wire_order (Sequence | None)

  • show_all_wires (bool)

  • show_wire_types (bool)

  • decimals (int | None)

  • style (str | None)

  • max_length (int | None)

  • level (Literal['top', 'user', 'device', 'gradient'] | int | slice)

Examples

By default, Hybridlane draws quantum circuits with wire icons and default colors.

dev = qp.device("bosonicqiskit.hybrid", max_fock_level=8)

@qp.qnode(dev)
def circuit(n):
    for j in range(n):
        qp.X(0)
        hl.JaynesCummings(np.pi / (2 * np.sqrt(j + 1)), np.pi / 2, [0, 1])

    return hl.expval(hl.NumberOperator(1))

n = 5
hl.draw_mpl(circuit, style="sketch")(n)
../../_images/ex_jc_circuit.png

Furthermore, icon colors can be adjusted from their defaults (say to color different motional modes of an ion trap). Note that Hybridlane also has a special notation for “qubit-conditioned” gates like \(CD\).

@qp.qnode(dev)
def circuit(n):
    qp.H(0)
    hl.Rotation(0.5, 1)

    for i in range(n):
        hl.ConditionalDisplacement(0.5, 0, [0, 2 + i])

    return hl.expval(hl.NumberOperator(n))

icon_colors = {
    2: "tomato",
    3: "orange",
    4: "gold",
    5: "lime",
    6: "turquoise",
}

hl.draw_mpl(circuit, wire_icon_colors=icon_colors, style="sketch")(5)
../../_images/colored_circuit.png

Finally, if you don’t like pretty icons, you can disable them.

@qp.qnode(dev)
def circuit(n):
    qp.H(0)
    hl.Rotation(0.5, 1)

    for i in range(n):
        hl.ConditionalDisplacement(0.5, 0, [0, 2 + i])

    return hl.expval(hl.NumberOperator(n))

hl.draw_mpl(circuit, show_wire_types=False, style="sketch")(5)
../../_images/no_icons.png
hybridlane.to_openqasm(qnode, rotations=True, precision=None, strict=False, indent=4, level='user')[source]

Converts a circuit to an OpenQASM 3.0 program

By default, the output will be a superset of the OpenQASM standard with extra features and language extensions that capture hybrid CV-DV programs. These modifications are detailed in the documentation.

If you would like the output to be strictly compliant with OpenQASM 3.0, you can pass the strict=True flag, which will

  1. Replace measure_x and measure_n keywords with equivalent defcal

    statements and function calls.

  2. Remove all qumode keywords, replacing them with qubit. This has the

    effect of erasing the type information of the program.

Note

Qubit measurements are assumed to be performed in the computational basis, while qumode measurements are determined from the BasisMap of each measurement. If sampling an observable, this function can provide the gates necessary to diagonalize each observable by setting rotations=True. Only wires that are actually measured will have measurement statements. Finally, non-overlapping measurements will be grouped together as much as possible and measured on the same call to state_prep(); however, the resulting program may have multiple executions of the tape as needed to accomodate all the measurements.

Parameters:
  • qnode – The QNode to be converted to OpenQASM

  • rotations (bool) – Include diagonalizing gates for an observable prior to measurement. This applies both to qubit observables and qumode observables.

  • precision (int | None) – An optional number of decimal places to use when recording the angle parameters of each gate

  • strict (bool) – Forces the output to be strictly compliant with the OpenQASM 3.0 parser.

  • indent (int) – Number of spaces to indent the program by

  • level (str | int | slice) – The level of the tape to construct. This is passed to construct_tape().

Returns:

A string containing the program in OpenQASM 3.0

Return type:

Callable[[Any], str]

Example

>>> @qp.qnode(qp.device("default.hybrid", fock_level=8))
... def circuit():
...     qp.H(0)
...     hl.ConditionalDisplacement(0.5, 0, [0, 1])
...     return hl.expval(hl.P(1))
>>> qasm = hl.to_openqasm(circuit)()
>>> print(qasm)
OPENQASM 3.0;
include "stdgates.inc";
include "cvstdgates.inc";

qubit[1] q;
qumode[1] m;

def state_prep() {
    reset q;
    reset m;
    h q[0];
    cv_cd(0.5, 0) q[0], m[0];
}

state_prep();
cv_r(1.5707963267948966) m[0];
float c0 = measure_x m[0];
hybridlane.density_matrix(wires=None)[source]

Density matrix measurement

Analogous to Pennylane’s density matrix measurement (qp.density_matrix()), returning the density matrix of the device across the specified wires. If no wires are specified, returns the density matrix across all wires.

Example

>>> circuit()
array([[0.5   +0.j, 0.0374+0.j],
       [0.0374+0.j, 0.5   +0.j]])
Parameters:

wires (pennylane.wires.WiresLike | None)

Return type:

DensityMatrixMP

hybridlane.expval(op)[source]

Expectation value of the supplied observable

Parameters:

op (Operator | pennylane.ops.mid_measure.MeasurementValue)

Return type:

ExpectationMP

hybridlane.var(op)[source]

Variance of the supplied observable

Parameters:

op (Operator | pennylane.ops.mid_measure.MeasurementValue)

Return type:

VarianceMP

hybridlane.qcond(op, control_wires)[source]

Creates a qubit-conditioned operator

For a unitary gate, this is the symbolic map \(e^{-i\theta G} \mapsto e^{-i\theta G \otimes_q Z_q}\) where \(q\) enumerates the qubit control wires. For a general callable, this creates a wrapper that applies the function and then applies the qubit-conditioned version of all operators in the resulting tape.

Example

>>> hl.qcond(hl.D(0.123, 0, wires="m"), control_wires="q")
ConditionalDisplacement(0.123, 0, wires=['q', 'm'])

This also works with some qubit gates:

>>> hl.qcond(qp.GlobalPhase(0.123), control_wires=1)
RZ(0.246, wires=[1])
>>> hl.qcond(qp.RZ(0.123, wires=0), control_wires=1)
IsingZZ(0.123, wires=[1, 0])
Parameters:
hybridlane.AJC

Anti-Jaynes-Cummings gate

\[AJC(\theta, \varphi) = \exp[-i\theta(e^{i\varphi}\sigma_+ \ad + e^{-i\varphi}\sigma_- a)]\]

See also

This is an alias of AntiJaynesCummings

hybridlane.CBS

Qubit-conditioned beamsplitter \(CBS(\theta, \varphi)\)

\[CBS(\theta, \varphi) = \exp[-i\frac{\theta}{2}\sigma_z (e^{i\varphi}\ad b + e^{-i\varphi} ab^\dagger)]\]

See also

This is an alias for ConditionalBeamsplitter

hybridlane.CD

Conditional displacement (CD) gate

\[CD(\alpha) = e^{(\alpha\ad - \alpha^*a)Z}\]

This is an alias for ConditionalDisplacement

hybridlane.CP

Conditional parity (CP) gate

\[CP = e^{-i\frac{\pi}{2}\hat{n}Z}\]

This is an alias for ConditionalParity

hybridlane.CR

Conditional rotation (CR) gate

\[CR(\theta) = e^{-i\frac{\theta}{2}\hat{n}Z}\]

This is an alias for ConditionalRotation

hybridlane.CS

Conditional squeezing (CS) gate

\[CS(\zeta) = \exp\left[\frac{1}{2}Z (\zeta^* a^2 - \zeta (\ad)^2)\right]\]

This is an alias for ConditionalSqueezing

hybridlane.CSUM

Qubit-conditioned two-mode sum gate \(CSUM(\lambda)\)

\[CSUM(\lambda) = \exp[\frac{\lambda}{2}\sigma_z(a + \ad)(b^\dagger - b)]\]

See also

This is an alias for ConditionalTwoModeSum

hybridlane.CTMS

Qubit-conditioned two-mode squeezing \(CTMS(\xi)\)

\[CTMS(\xi) = \exp[\sigma_z (\xi \ad b^\dagger - \xi^* ab)]\]

See also

This is an alias for ConditionalTwoModeSqueezing

hybridlane.ECD

Echoed-conditional displacement (ECD) gate

\[ECD(\alpha) = X~CD(\alpha/2)\]

This is an alias for EchoedConditionalDisplacement

hybridlane.JC

Jaynes-Cummings gate

\[JC(\theta, \varphi) = \exp[-i\theta(e^{i\varphi}\sigma_- \ad + e^{-i\varphi}\sigma_+ a)]\]

See also

This is an alias of JaynesCummings

hybridlane.SQR

number-Selective Qubit Rotation (SQR) gate`

\[SQR(\theta, \varphi) = R_{\varphi}(\theta) \otimes \ket{n}\bra{n}\]

See also

This is an alias for SelectiveQubitRotation

hybridlane.XCD

X-Conditional displacement (xCD) gate

\[xCD(\alpha) = e^{(\alpha\ad - \alpha^*a)X}\]

This is an alias for ConditionalXDisplacement

hybridlane.YCD

Y-Conditional displacement (yCD) gate

\[yCD(\alpha) = e^{(\alpha\ad - \alpha^*a)Y}\]

This is an alias for ConditionalYDisplacement

hybridlane.Blue

Blue sideband gate

\[AJC(\theta, \varphi) = \exp[-i\theta(e^{i\varphi}\sigma_+ \ad + e^{-i\varphi}\sigma_- a)]\]

See also

This is an alias of AntiJaynesCummings

hybridlane.Red

Red sideband gate

\[JC(\theta, \varphi) = \exp[-i\theta(e^{i\varphi}\sigma_- \ad + e^{-i\varphi}\sigma_+ a)]\]

See also

This is an alias of JaynesCummings

hybridlane.BS

Beamsplitter gate \(BS(\theta, \varphi)\)

\[BS(\theta, \varphi) = \exp\left[-i \frac{\theta}{2} (e^{i\varphi} \ad b + e^{-i\varphi}ab^\dagger)\right]\]

See also

This is an alias of Beamsplitter

hybridlane.SNAP

Selective Number-dependent Arbitrary Phase (SNAP) gate

\[SNAP(\varphi, n) = e^{-i \varphi \ket{n}\bra{n}}\]

See also

This is an alias for SelectiveNumberArbitraryPhase

hybridlane.SUM

Two-mode summing gate \(SUM(\lambda)\)

\[SUM(\lambda) = \exp[\frac{\lambda}{2}(a + \ad)(b^\dagger - b)]\]

See also

This is an alias of TwoModeSum

hybridlane.TMS

Phase space two-mode squeezing \(TMS(r, \varphi)\)

\[TMS(r, \varphi) = \exp\left[r (e^{i\phi} \ad b^\dagger - e^{-i\phi} ab\right].\]

See also

This is an alias of TwoModeSqueezing

hybridlane.A

Annihilation operator \(a\)

See also

This is an alias of AnnihilationOp

hybridlane.Ad

Creation operator \(\ad\)

See also

This is an alias of CreationOp

hybridlane.C

Cubic phase shift gate \(C(r)\)

\[C(r) = e^{-i r \hat{x}^3}.\]

See also

This is an alias of CubicPhase

hybridlane.D

Phase space displacement gate \(D(\alpha)\)

\[D(\alpha) = \exp[\alpha \ad -\alpha^* a]\]

See also

This is an alias of Displacement

hybridlane.F

Fourier gate

\[F = e^{-i\frac{\pi}{2}\hat{n}}\]

See also

This is an alias of Fourier

hybridlane.K

Kerr gate \(K(\kappa)\)

\[K(\kappa) = \exp[-i \kappa \hat{n}^2]\]

See also

This is an alias of Kerr

hybridlane.N

Number operator \(\hat{n}\)

See also

This is an alias for NumberOperator

hybridlane.P

Momentum operator \(\hat{p}\)

See also

This is an alias for QuadP

hybridlane.R

Phase space rotation gate \(R(\theta)\)

\[R(\theta) = \exp[-i\theta \hat{n}]\]

See also

This is an alias of Rotation

hybridlane.S

Phase space squeezing gate \(S(\zeta)\)

\[S(\zeta) = \exp\left[\frac{1}{2}(\zeta^* a^2 - \zeta(\ad)^2)\right]\]

See also

This is an alias of Squeezing

hybridlane.X

Position operator \(\hat{x}\)

See also

This is an alias for QuadX

hybridlane.qubits

Create a dictionary of qubit registers.

This has the same usage as pennylane.registers(), but the resulting wires are wrapped in TypedWires with type Qubit.

Example

>>> reg = hl.qubits({"alice": 2})
{'alice': TypedWires(wires=Wires([0, 1]), wire_type=Qubit())}
hybridlane.qumodes

Create a dictionary of qumode registers.

This has the same usage as pennylane.registers(), but the resulting wires are wrapped in TypedWires with type Qumode.

Example

>>> reg = hl.qumodes({"bob": 2})
{'bob': TypedWires(wires=Wires([0, 1]), wire_type=Qumode())}
hybridlane.__version__