hybridlane¶
Submodules¶
Attributes¶
Conditional parity (CP) gate |
|
Qubit-conditioned beamsplitter \(CBS(\theta, \varphi)\) |
|
Qubit-conditioned two-mode sum gate \(CSUM(\lambda)\) |
|
Qubit-conditioned two-mode squeezing \(CTMS(\xi)\) |
|
Anti-Jaynes-Cummings gate |
|
Conditional displacement (CD) gate |
|
Conditional rotation (CR) gate |
|
Conditional squeezing (CS) gate |
|
Echoed-conditional displacement (ECD) gate |
|
Jaynes-Cummings gate |
|
number-Selective Qubit Rotation (SQR) gate` |
|
X-Conditional displacement (xCD) gate |
|
Y-Conditional displacement (yCD) gate |
|
Blue sideband gate |
|
Red sideband gate |
|
Fourier gate |
|
Number operator \(\hat{n}\) |
|
Momentum operator \(\hat{p}\) |
|
Position operator \(\hat{x}\) |
|
Beamsplitter gate \(BS(\theta, \varphi)\) |
|
Phase space two-mode squeezing \(TMS(r, \varphi)\) |
|
Two-mode summing gate \(SUM(\lambda)\) |
|
Phase space displacement gate \(D(\alpha)\) |
|
Phase space squeezing gate \(S(\zeta)\) |
|
Phase space rotation gate \(R(\theta)\) |
|
Kerr gate \(K(\kappa)\) |
|
Cubic phase shift gate \(C(r)\) |
|
Selective Number-dependent Arbitrary Phase (SNAP) gate |
Classes¶
Mixin for hybrid CV-DV gates |
|
Symbolic operator denoting a qubit-conditioned operator |
|
Qubit-conditioned number parity gate \(CP\) |
|
Qubit-conditioned beamsplitter \(CBS(\theta, \varphi)\) |
|
Qubit-conditioned two-mode squeezing \(CTMS(\xi)\) |
|
Qubit-conditioned two-mode sum gate \(CSUM(\lambda)\) |
|
Anti-Jaynes-cummings gate \(AJC(\theta, \varphi)\), also known as Blue-Sideband |
|
Symmetric conditional displacement gate \(CD(\alpha)\) |
|
Qubit-conditioned phase-space rotation \(CR(\theta)\) |
|
Qubit-conditioned squeezing gate \(CS(\zeta)\) |
|
X-Conditional displacement gate \(xCD(\alpha)\) |
|
Y-Conditional displacement gate \(yCD(\alpha)\) |
|
Echoed conditional displacement gate \(ECD(\alpha)\) |
|
Jaynes-cummings gate \(JC(\theta, \varphi)\), also known as Red-Sideband |
|
Rabi interaction \(RB(\theta)\) |
|
number-Selective Qubit Rotation (SQR) gate \(SQR(\theta, \varphi, n)\) |
|
Continuous-variable Fourier gate \(F\) |
|
Continuous-variable SWAP between two qumodes |
|
The number state observable \(\ket{n}\bra{n}\). |
|
The photon number observable \(\langle \hat{n}\rangle\). |
|
The generalized quadrature observable \(\hat{x}_\phi = \hat{x} \cos\phi + \hat{p} \sin\phi\) |
|
The momentum quadrature observable \(\hat{p}\). |
|
The position quadrature observable \(\hat{x}\). |
|
Beamsplitter gate \(BS(\theta, \varphi)\) |
|
Phase space two-mode squeezing \(TMS(r, \varphi)\) |
|
Two-mode summing gate \(SUM(\lambda)\) |
|
Phase space displacement gate \(D(\alpha)\) |
|
Phase space squeezing gate \(S(\zeta)\) |
|
Phase space rotation gate \(R(\theta)\) |
|
Kerr gate \(K(\kappa)\) |
|
Cubic phase shift gate \(C(r)\) |
|
Selective Number-dependent Arbitrary Phase (SNAP) gate \(SNAP(\varphi, n)\) |
|
Prepares a definite Fock state from the vacuum |
|
GKP-state preparation on a qumode using non-Abelian QSP |
|
Cat-state preparation on a qumode using non-Abelian QSP |
Functions¶
|
Draws a circuit using matplotlib |
|
Converts a circuit to an OpenQASM 3.0 program |
|
Expectation value of the supplied observable |
|
Variance of the supplied observable |
|
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
qml.draw_mpl.max_length (int | None)
level (Literal['top', 'user', 'device', 'gradient'] | int | slice | None)
- 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
qml.draw_mpl.- Returns:
A function that when called, produces the same output as
qml.draw_mpl- Parameters:
Examples
By default, Hybridlane draws quantum circuits with wire icons and default colors.
dev = qml.device("bosonicqiskit.hybrid", max_fock_level=8) @qml.qnode(dev) def circuit(n): for j in range(n): qml.X(0) hqml.JaynesCummings(np.pi / (2 * np.sqrt(j + 1)), np.pi / 2, [0, 1]) return hqml.expval(hqml.NumberOperator(1)) n = 5 hqml.draw_mpl(circuit, style="sketch")(n)
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.
@qml.qnode(dev) def circuit(n): qml.H(0) hqml.Rotation(0.5, 1) for i in range(n): hqml.ConditionalDisplacement(0.5, 0, [0, 2 + i]) return hqml.expval(hqml.NumberOperator(n)) icon_colors = { 2: "tomato", 3: "orange", 4: "gold", 5: "lime", 6: "turquoise", } hqml.draw_mpl(circuit, wire_icon_colors=icon_colors, style="sketch")(5)
Finally, if you don’t like pretty icons, you can disable them.
@qml.qnode(dev) def circuit(n): qml.H(0) hqml.Rotation(0.5, 1) for i in range(n): hqml.ConditionalDisplacement(0.5, 0, [0, 2 + i]) return hqml.expval(hqml.NumberOperator(n)) hqml.draw_mpl(circuit, show_wire_types=False, style="sketch")(5)
- 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=Trueflag, which will- Replace
measure_xandmeasure_nkeywords with equivalentdefcal statements and function calls.
- Replace
- Remove all
qumodekeywords, replacing them withqubit. This has the effect of erasing the type information of the program.
- Remove all
Note
Qubit measurements are assumed to be performed in the computational basis, while qumode measurements are determined from the
BasisSchemaof each measurement. If sampling an observable, this function can provide the gates necessary to diagonalize each observable by settingrotations=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 tostate_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 | None)
- Returns:
A string containing the program in OpenQASM 3.0
- Return type:
Callable[[Any], str]
Example
>>> @qml.qnode(qml.device("bosonicqiskit.hybrid", max_fock_level=8)) ... def circuit(): ... qml.H(0) ... hqml.ConditionalDisplacement(0.5, 0, [0, 1]) ... return hqml.expval(hqml.P(1)) >>> qasm = hqml.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.expval(op)[source]¶
Expectation value of the supplied observable
- Parameters:
op (Operator | pennylane.ops.mid_measure.MeasurementValue)
- Return type:
- hybridlane.var(op)[source]¶
Variance of the supplied observable
- Parameters:
op (Operator | pennylane.ops.mid_measure.MeasurementValue)
- Return type:
- hybridlane.__hybrid_all__ = ['CP', 'ConditionalParity', 'CBS', 'CSUM', 'CTMS', 'ConditionalBeamsplitter',...¶
- hybridlane.qcond(op, control_wires)[source]¶
- Parameters:
op (Operator | Callable)
control_wires (pennylane.wires.WiresLike)
- hybridlane.__qumode_all__ = ['Fourier', 'F', 'ModeSwap', 'FockStateProjector', 'N', 'NumberOperator', 'P', 'QuadOperator',...¶
- hybridlane.__all__ = ['attributes', 'Hybrid', 'QubitConditioned', 'qcond', 'CP', 'ConditionalParity', 'CBS', 'CSUM',...¶
- hybridlane.CP¶
Conditional parity (CP) gate
\[CP = e^{-i\frac{\pi}{2}\hat{n}Z}\]This is an alias for
ConditionalParity
- 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.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.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.CD¶
Conditional displacement (CD) gate
\[CD(\alpha) = e^{(\alpha\ad - \alpha^*a)Z}\]This is an alias for
ConditionalDisplacement
- 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.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.F¶
Fourier gate
\[F = e^{-i\frac{\pi}{2}\hat{n}}\]See also
This is an alias of
JaynesCummings
- hybridlane.N¶
Number operator \(\hat{n}\)
See also
This is an alias for
NumberOperator
- 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.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.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.D¶
Phase space displacement gate \(D(\alpha)\)
\[D(\alpha) = \exp[\alpha \ad -\alpha^* a]\]See also
This is an alias of
Displacement
- 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.R¶
Phase space rotation gate \(R(\theta)\)
\[R(\theta) = \exp[-i\theta \hat{n}]\]See also
This is an alias of
Rotation
- hybridlane.K¶
Kerr gate \(K(\kappa)\)
\[K(\kappa) = \exp[-i \kappa \hat{n}^2]\]See also
This is an alias of
Kerr
- 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.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