qutip_qip.operations
Operations on quantum circuits.
Classes
|
Base class for a quantum gate, concrete gate classes need to be defined as subclasses. |
|
Representation of a quantum measurement, with its required parameters, and target qubits. |
|
|
|
Single-qubit X gate. |
|
Single-qubit Y gate. |
|
Single-qubit Z gate. |
|
Single-qubit rotation RX. |
|
Single-qubit rotation RY. |
|
Single-qubit rotation RZ. |
|
Hadamard gate. |
alias of |
|
|
\(\sqrt{X}\) gate. |
|
S gate or \(\sqrt{Z}\) gate. |
|
T gate or \(\sqrt[4]{Z}\) gate. |
|
QASMU gate. |
|
SWAP gate. |
|
iSWAP gate. |
|
CNOT gate. |
|
\(\sqrt{\mathrm{SWAP}}\) gate. |
|
\(\sqrt{\mathrm{iSWAP}}\) gate. |
|
BERKELEY gate. |
|
SWAPALPHA gate. |
|
Mølmer–Sørensen gate. |
|
TOFFOLI gate. |
|
FREDKIN gate. |
|
CNOT gate. |
|
Controlled CSIGN gate. |
|
Controlled X rotation. |
|
Controlled Y rotation. |
|
Controlled Z rotation. |
|
Controlled Y gate. |
|
Controlled X gate. |
|
Controlled Z gate. |
|
Controlled S gate. |
|
Controlled T gate. |
|
CPHASE gate. |
Functions
|
Quantum object representing the Berkeley gate. |
|
Quantum object representing the CNOT gate. |
|
Create an N-qubit controlled gate from a single-qubit gate U with the given control and target qubits. |
|
Returns quantum object representing the controlled phase shift gate. |
|
Controlled S gate. |
|
Quantum object representing the CSIGN gate. |
|
Controlled T gate. |
|
Controlled Y gate. |
|
Controlled Z gate. |
|
Expand an operator to one that acts on a system with desired dimensions. |
|
Quantum object representing the Fredkin gate. |
|
Calculate the overall unitary matrix for a given list of unitary operations. |
|
Returns quantum object representing the global phase shift gate. |
|
Quantum object representing the N-qubit Hadamard gate. |
|
Quantum object representing the iSWAP gate. |
|
Quantum object of a Mølmer–Sørensen gate. |
|
Returns quantum object representing the phase shift gate. |
|
QASM U-gate as defined in the OpenQASM standard. |
|
Single qubit rotation driving by Rabi oscillation with 0 detune. |
|
Generates the Clifford group on a single qubit, using the presentation of the group given by Ross and Selinger (http://www.mathstat.dal.ca/~selinger/newsynth/). |
|
Single-qubit rotation for operator op with angle phi. |
|
Single-qubit rotation for operator sigmax with angle phi. |
|
Single-qubit rotation for operator sigmay with angle phi. |
|
Single-qubit rotation for operator sigmaz with angle phi. |
|
Single-qubit rotation also called Phase gate or the Z90 gate. |
|
Quantum object representing the SNOT (Hadamard) gate. |
|
Quantum object representing the square root iSWAP gate. |
|
Single-qubit square root NOT gate. |
|
Quantum object representing the square root SWAP gate. |
|
Quantum object representing the SWAP gate. |
|
Quantum object representing the SWAPalpha gate. |
|
Single-qubit rotation related to the S gate by the relationship S=T*T. |
|
Quantum object representing the Toffoli gate. |
|
Pauli-X gate or sigmax operator. |
|
Pauli-Y gate or sigmay operator. |
|
Pauli-Z gate or sigmaz operator. |
- class qutip_qip.operations.BERKELEY(targets, **kwargs)[source]
Bases:
TwoQubitGate
BERKELEY gate.
\[\begin{split}\begin{pmatrix} \cos(\frac{\pi}{8}) & 0 & 0 & i\sin(\frac{\pi}{8}) \\ 0 & \cos(\frac{3\pi}{8}) & i\sin(\frac{3\pi}{8}) & 0 \\ 0 & i\sin(\frac{3\pi}{8}) & \cos(\frac{3\pi}{8}) & 0 \\ i\sin(\frac{\pi}{8}) & 0 & 0 & \cos(\frac{\pi}{8}) \end{pmatrix}\end{split}\]Examples
>>> from qutip_qip.operations import BERKELEY >>> BERKELEY([0, 1]).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[0.92388+0.j 0. +0.j 0. +0.j 0. +0.38268j] [0. +0.j 0.38268+0.j 0. +0.92388j 0. +0.j ] [0. +0.j 0. +0.92388j 0.38268+0.j 0. +0.j ] [0. +0.38268j 0. +0.j 0. +0.j 0.92388+0.j ]]
- class qutip_qip.operations.CNOT(controls, targets, **kwargs)[source]
Bases:
_OneControlledGate
CNOT gate.
Examples
>>> from qutip_qip.operations import CNOT >>> CNOT(0, 1).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True Qobj data = [[1. 0. 0. 0.] [0. 1. 0. 0.] [0. 0. 0. 1.] [0. 0. 1. 0.]]
- class qutip_qip.operations.CPHASE(controls, targets, arg_value, control_value=1, **kwargs)[source]
Bases:
_OneControlledGate
CPHASE gate.
\[\begin{split}\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i\theta} \\ \end{pmatrix}\end{split}\]Examples
>>> from qutip_qip.operations import CPHASE >>> CPHASE(0, 1, np.pi/2).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 1.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 1.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 0.+1.j]]
- class qutip_qip.operations.CSIGN(controls, targets, **kwargs)[source]
Bases:
_OneControlledGate
Controlled CSIGN gate. Identical to the CZ gate.
Examples
>>> from qutip_qip.operations import CSIGN >>> CSIGN(0, 1).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True Qobj data = [[ 1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. 0. -1.]]
- class qutip_qip.operations.CZ(controls, targets, **kwargs)[source]
Bases:
_OneControlledGate
Controlled Z gate. Identical to the CSIGN gate.
Examples
>>> from qutip_qip.operations import CZ >>> CSIGN(0, 1).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True Qobj data = [[ 1. 0. 0. 0.] [ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. 0. -1.]]
- class qutip_qip.operations.FREDKIN(targets, **kwargs)[source]
Bases:
Gate
FREDKIN gate.
Examples
>>> from qutip_qip.operations import FREDKIN >>> FREDKIN([0, 1, 2]).get_compact_qobj() Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True Qobj data = [[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.]]
- class qutip_qip.operations.Gate(name=None, targets=None, controls=None, arg_value=None, control_value=None, classical_controls=None, classical_control_value: Optional[int] = None, arg_label=None, **kwargs)[source]
Bases:
object
Base class for a quantum gate, concrete gate classes need to be defined as subclasses.
- Parameters
- targetslist or int
The target qubits fo the gate.
- controlslist or int
The controlling qubits of the gate.
- arg_valueobject
Argument value of the gate. It will be saved as an attributes and can be accessed when generating the :obj:qutip.Qobj.
- classical_controlsint or list of int, optional
Indices of classical bits to control the unitary operator.
- control_valueint, optional
The decimal value of controlling bits for executing the unitary operator on the target qubits. E.g. if the gate should be executed when the zero-th bit is 1,
controll_value=1
; If the gate should be executed when the two bits are 1 and 0,controll_value=2
.- classical_control_valueint, optional
The decimal value of controlling classical bits for executing the unitary operator on the target qubits. E.g. if the gate should be executed when the zero-th bit is 1,
controll_value=1
; If the gate should be executed when the two bits are 1 and 0,controll_value=2
. The default is2**len(classical_controls)-1
(i.e. all classical controls are 1).- arg_labelstring
Label for the argument, it will be shown in the circuit plot, representing the argument value provided to the gate, e.g, if
arg_label="\phi" the latex name for the gate in the circuit plot will be ``$U(\phi)$
.- namestring, optional
The name of the gate. This is kept for backward compatibility to identify different gates. In most cases it is identical to the class name, but that is not guaranteed. It is recommended to use
isinstance
orissubclass
to identify a gate rather than comparing the name string.
- get_all_qubits()[source]
Return a list of all qubits that the gate operator acts on. The list concatenates the two lists representing the controls and the targets qubits while retains the order.
- Returns
- targets_listlist of int
A list of all qubits, including controls and targets.
- get_compact_qobj()[source]
Get the compact
qutip.Qobj
representation of the gate operator, ignoring the controls and targets. In the unitary representation, it always assumes that the first few qubits are controls, then targets.- Returns
- qobj
qutip.Qobj
The compact gate operator as a unitary matrix.
- qobj
- get_qobj(num_qubits=None, dims=None)[source]
Get the
qutip.Qobj
representation of the gate operator. The operator is expanded to the full Herbert space according to the controls and targets qubits defined for the gate.- Parameters
- num_qubitsint, optional
The number of qubits. If not given, use the minimal number of qubits required by the target and control qubits.
- dimslist, optional
A list representing the dimensions of each quantum system. If not given, it is assumed to be an all-qubit system.
- Returns
- qobj
qutip.Qobj
The compact gate operator as a unitary matrix.
- qobj
- class qutip_qip.operations.H(targets, **kwargs)[source]
Bases:
SingleQubitGate
Hadamard gate.
Examples
>>> from qutip_qip.operations import H >>> H(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = True Qobj data = [[ 0.70711 0.70711] [ 0.70711 -0.70711]]
- class qutip_qip.operations.ISWAP(targets, **kwargs)[source]
Bases:
TwoQubitGate
iSWAP gate.
Examples
>>> from qutip_qip.operations import ISWAP >>> ISWAP([0, 1]).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[1.+0.j 0.+0.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+1.j 0.+0.j] [0.+0.j 0.+1.j 0.+0.j 0.+0.j] [0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
- class qutip_qip.operations.MS(targets, arg_value, **kwargs)[source]
Bases:
TwoQubitGate
Mølmer–Sørensen gate.
\[\begin{split}\begin{pmatrix} \cos(\frac{\theta}{2}) & 0 & 0 & -ie^{-i2\phi}\sin(\frac{\theta}{2}) \\ 0 & \cos(\frac{\theta}{2}) & -i\sin(\frac{\theta}{2}) & 0 \\ 0 & -i\sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) & 0 \\ -ie^{i2\phi}\sin(\frac{\theta}{2}) & 0 & 0 & \cos(\frac{\theta}{2}) \end{pmatrix}\end{split}\]Examples
>>> from qutip_qip.operations import MS >>> MS([0, 1], (np.pi/2, 0)).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[0.70711+0.j 0. +0.j 0. +0.j 0. -0.70711j] [0. +0.j 0.70711+0.j 0. -0.70711j 0. +0.j ] [0. +0.j 0. -0.70711j 0.70711+0.j 0. +0.j ] [0. -0.70711j 0. +0.j 0. +0.j 0.70711+0.j ]]
- class qutip_qip.operations.Measurement(name, targets=None, index=None, classical_store=None)[source]
Bases:
object
Representation of a quantum measurement, with its required parameters, and target qubits.
- Parameters
- namestring
Measurement name.
- targetslist or int
Gate targets.
- classical_storeint
Result of the measurment is stored in this classical register of the circuit.
- measurement_comp_basis(state)[source]
Measures a particular qubit (determined by the target) whose ket vector/ density matrix is specified in the computational basis and returns collapsed_states and probabilities (retains full dimension).
- Parameters
- stateket or oper
state to be measured on specified by ket vector or density matrix
- Returns
- collapsed_statesList of Qobjs
the collapsed state obtained after measuring the qubits and obtaining the qubit specified by the target in the state specified by the index.
- probabilitiesList of floats
the probability of measuring a state in a the state specified by the index.
- class qutip_qip.operations.QASMU(targets, arg_value=None, **kwargs)[source]
Bases:
SingleQubitGate
QASMU gate.
\[U(\theta, \phi, \gamma) = RZ(\phi) RY(\theta) RZ(\gamma)\]Examples
>>> from qutip_qip.operations import QASMU >>> QASMU(0, (np.pi/2, np.pi, np.pi/2)).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[-0.5-0.5j -0.5+0.5j] [ 0.5+0.5j -0.5+0.5j]]
- class qutip_qip.operations.R(targets, arg_value=None, **kwargs)[source]
Bases:
SingleQubitGate
Arbitrary single-qubit rotation
\[\begin{split}\begin{pmatrix} \cos(\frac{\theta}{2}) & -ie^{-i\phi} \sin(\frac{\theta}{2}) \\ -ie^{i\phi} \sin(\frac{\theta}{2}) & \cos(\frac{\theta}{2}) \end{pmatrix}\end{split}\]Examples
>>> from qutip_qip.operations import R >>> R(0, (np.pi/2, np.pi/2)).get_compact_qobj().tidyup() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[ 0.70711 -0.70711] [ 0.70711 0.70711]]
- class qutip_qip.operations.RX(targets, arg_value, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit rotation RX.
Examples
>>> from qutip_qip.operations import RX >>> RX(0, 3.14159/2).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[0.70711+0.j 0. -0.70711j] [0. -0.70711j 0.70711+0.j ]]
- class qutip_qip.operations.RY(targets, arg_value, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit rotation RY.
Examples
>>> from qutip_qip.operations import RY >>> RY(0, 3.14159/2).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[ 0.70711 -0.70711] [ 0.70711 0.70711]]
- class qutip_qip.operations.RZ(targets, arg_value, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit rotation RZ.
Examples
>>> from qutip_qip.operations import RZ >>> RZ(0, 3.14159/2).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[0.70711-0.70711j 0. +0.j ] [0. +0.j 0.70711+0.70711j]]
- class qutip_qip.operations.S(targets, **kwargs)[source]
Bases:
SingleQubitGate
S gate or \(\sqrt{Z}\) gate.
Examples
>>> from qutip_qip.operations import S >>> S(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[1.+0.j 0.+0.j] [0.+0.j 0.+1.j]]
- class qutip_qip.operations.SQRTISWAP(targets, **kwargs)[source]
Bases:
TwoQubitGate
\(\sqrt{\mathrm{iSWAP}}\) gate.
Examples
>>> from qutip_qip.operations import SQRTISWAP >>> SQRTISWAP([0, 1]).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[1. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0.70711+0.j 0. +0.70711j 0. +0.j ] [0. +0.j 0. +0.70711j 0.70711+0.j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 1. +0.j ]]
- class qutip_qip.operations.SQRTNOT(targets, **kwargs)[source]
Bases:
SingleQubitGate
\(\sqrt{X}\) gate.
Examples
>>> from qutip_qip.operations import SQRTNOT >>> SQRTNOT(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[0.5+0.5j 0.5-0.5j] [0.5-0.5j 0.5+0.5j]]
- class qutip_qip.operations.SQRTSWAP(targets, **kwargs)[source]
Bases:
TwoQubitGate
\(\sqrt{\mathrm{SWAP}}\) gate.
Examples
>>> from qutip_qip.operations import SQRTSWAP >>> SQRTSWAP([0, 1]).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[1. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0.5+0.5j 0.5-0.5j 0. +0.j ] [0. +0.j 0.5-0.5j 0.5+0.5j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 1. +0.j ]]
- class qutip_qip.operations.SWAP(targets, **kwargs)[source]
Bases:
TwoQubitGate
SWAP gate.
Examples
>>> from qutip_qip.operations import SWAP >>> SWAP([0, 1]).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = True Qobj data = [[1. 0. 0. 0.] [0. 0. 1. 0.] [0. 1. 0. 0.] [0. 0. 0. 1.]]
- class qutip_qip.operations.SWAPALPHA(targets, arg_value, **kwargs)[source]
Bases:
TwoQubitGate
SWAPALPHA gate.
\[\begin{split}\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \frac{1 + e^{i\pi\alpha}}{2} & \frac{1 - e^{i\pi\alpha}}{2} & 0 \\ 0 & \frac{1 - e^{i\pi\alpha}}{2} & \frac{1 + e^{i\pi\alpha}}{2} & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]Examples
>>> from qutip_qip.operations import SWAPALPHA >>> SWAPALPHA([0, 1], 0.5).get_compact_qobj() Quantum object: dims = [[2, 2], [2, 2]], shape = (4, 4), type = oper, isherm = False Qobj data = [[1. +0.j 0. +0.j 0. +0.j 0. +0.j ] [0. +0.j 0.5+0.5j 0.5-0.5j 0. +0.j ] [0. +0.j 0.5-0.5j 0.5+0.5j 0. +0.j ] [0. +0.j 0. +0.j 0. +0.j 1. +0.j ]]
- class qutip_qip.operations.T(targets, **kwargs)[source]
Bases:
SingleQubitGate
T gate or \(\sqrt[4]{Z}\) gate.
Examples
>>> from qutip_qip.operations import T >>> T(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = False Qobj data = [[1. +0.j 0. +0.j ] [0. +0.j 0.70711+0.70711j]]
- class qutip_qip.operations.TOFFOLI(targets, **kwargs)[source]
Bases:
Gate
TOFFOLI gate.
Examples
>>> from qutip_qip.operations import TOFFOLI >>> TOFFOLI([0, 1, 2]).get_compact_qobj() Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True Qobj data = [[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.]]
- class qutip_qip.operations.X(targets, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit X gate.
Examples
>>> from qutip_qip.operations import X >>> X(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = True Qobj data = [[0. 1.] [1. 0.]]
- class qutip_qip.operations.Y(targets, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit Y gate.
Examples
>>> from qutip_qip.operations import Y >>> Y(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = True Qobj data = [[0.+0.j 0.-1.j] [0.+1.j 0.+0.j]]
- class qutip_qip.operations.Z(targets, **kwargs)[source]
Bases:
SingleQubitGate
Single-qubit Z gate.
Examples
>>> from qutip_qip.operations import Z >>> Z(0).get_compact_qobj() Quantum object: dims = [[2], [2]], shape = (2, 2), type = oper, isherm = True Qobj data = [[ 1. 0.] [ 0. -1.]]
- qutip_qip.operations.berkeley(N=None, targets=[0, 1])[source]
Quantum object representing the Berkeley gate.
- Returns
- berkeley_gateqobj
Quantum object representation of Berkeley gate
Examples
>>> berkeley() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True Qobj data = [[ cos(pi/8).+0.j 0.+0.j 0.+0.j 0.+sin(pi/8).j] [ 0.+0.j cos(3pi/8).+0.j 0.+sin(3pi/8).j 0.+0.j] [ 0.+0.j 0.+sin(3pi/8).j cos(3pi/8).+0.j 0.+0.j] [ 0.+sin(pi/8).j 0.+0.j 0.+0.j cos(pi/8).+0.j]]
- qutip_qip.operations.cnot(N=None, control=0, target=1)[source]
Quantum object representing the CNOT gate.
- Returns
- cnot_gateqobj
Quantum object representation of CNOT gate
Examples
>>> cnot() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j] [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j]]
- qutip_qip.operations.controlled_gate(U, controls=0, targets=1, N=None, control_value=1)[source]
Create an N-qubit controlled gate from a single-qubit gate U with the given control and target qubits.
- Parameters
- U
qutip.Qobj
An arbitrary unitary gate.
- controlslist of int
The index of the first control qubit.
- targetslist of int
The index of the target qubit.
- Nint
The total number of qubits.
- control_valueint
The decimal value of the controlled qubits that activates the gate U.
- U
- Returns
- resultqobj
Quantum object representing the controlled-U gate.
- qutip_qip.operations.cphase(theta, N=2, control=0, target=1)[source]
Returns quantum object representing the controlled phase shift gate.
- Parameters
- thetafloat
Phase rotation angle.
- Ninteger
The number of qubits in the target space.
- controlinteger
The index of the control qubit.
- targetinteger
The index of the target qubit.
- Returns
- Uqobj
Quantum object representation of controlled phase gate.
- qutip_qip.operations.cs_gate(N=None, control=0, target=1)[source]
Controlled S gate.
- Returns
- result
qutip.Qobj
Quantum object for operator describing the rotation.
- result
- qutip_qip.operations.csign(N=None, control=0, target=1)[source]
Quantum object representing the CSIGN gate.
- Returns
- csign_gateqobj
Quantum object representation of CSIGN gate
Examples
>>> csign() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j -1.+0.j]]
- qutip_qip.operations.ct_gate(N=None, control=0, target=1)[source]
Controlled T gate.
- Returns
- result
qutip.Qobj
Quantum object for operator describing the rotation.
- result
- qutip_qip.operations.cy_gate(N=None, control=0, target=1)[source]
Controlled Y gate.
- Returns
- result
qutip.Qobj
Quantum object for operator describing the rotation.
- result
- qutip_qip.operations.cz_gate(N=None, control=0, target=1)[source]
Controlled Z gate.
- Returns
- result
qutip.Qobj
Quantum object for operator describing the rotation.
- result
- qutip_qip.operations.expand_operator(oper, N=None, targets=None, dims=None, cyclic_permutation=False, dtype=None)[source]
Expand an operator to one that acts on a system with desired dimensions.
- Parameters
- oper
qutip.Qobj
An operator that act on the subsystem, has to be an operator and the dimension matches the tensored dims Hilbert space e.g. oper.dims =
[[2, 3], [2, 3]]
- dimslist
A list of integer for the dimension of each composite system. E.g
[2, 3, 2, 3, 4]
.- targetsint or list of int
The indices of subspace that are acted on. Permutation can also be realized by changing the orders of the indices.
- Nint
Deprecated. Number of qubits. Please use dims.
- cyclic_permutationboolean, optional
Deprecated. Expand for all cyclic permutation of the targets. E.g. if
N=3
and oper is a 2-qubit operator, the result will be a list of three operators, each acting on qubits 0 and 1, 1 and 2, 2 and 0.- dtypestr, optional
Data type of the output Qobj. Only for qutip version larger than 5.
- oper
- Returns
- expanded_oper
qutip.Qobj
The expanded operator acting on a system with desired dimension.
- expanded_oper
Examples
>>> from qutip_qip.operations import expand_operator, x_gate, cnot >>> import qutip >>> expand_operator(x_gate(), dims=[2,3], targets=[0]) Quantum object: dims = [[2, 3], [2, 3]], shape = (6, 6), type = oper, isherm = True Qobj data = [[0. 0. 0. 1. 0. 0.] [0. 0. 0. 0. 1. 0.] [0. 0. 0. 0. 0. 1.] [1. 0. 0. 0. 0. 0.] [0. 1. 0. 0. 0. 0.] [0. 0. 1. 0. 0. 0.]] >>> expand_operator(cnot(), dims=[2,2,2], targets=[1, 2]) Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True Qobj data = [[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. 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.]] >>> expand_operator(cnot(), dims=[2, 2, 2], targets=[2, 0]) Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = (8, 8), type = oper, isherm = True Qobj data = [[1. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 1. 0. 0.] [0. 0. 1. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 1.] [0. 0. 0. 0. 1. 0. 0. 0.] [0. 1. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 1. 0.] [0. 0. 0. 1. 0. 0. 0. 0.]]
- qutip_qip.operations.fredkin(N=None, control=0, targets=[1, 2])[source]
Quantum object representing the Fredkin gate.
- Returns
- fredkin_gateqobj
Quantum object representation of Fredkin gate.
Examples
>>> fredkin() Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
- qutip_qip.operations.gate_sequence_product(U_list, left_to_right=True, inds_list=None, expand=False)[source]
Calculate the overall unitary matrix for a given list of unitary operations.
- Parameters
- U_list: list
List of gates implementing the quantum circuit.
- left_to_right: Boolean, optional
Check if multiplication is to be done from left to right.
- inds_list: list of list of int, optional
If expand=True, list of qubit indices corresponding to U_list to which each unitary is applied.
- expand: Boolean, optional
Check if the list of unitaries need to be expanded to full dimension.
- Returns
- U_overallqobj
Unitary matrix corresponding to U_list.
- overall_indslist of int, optional
List of qubit indices on which U_overall applies.
- qutip_qip.operations.globalphase(theta, N=1)[source]
Returns quantum object representing the global phase shift gate.
- Parameters
- thetafloat
Phase rotation angle.
- Returns
- phase_gateqobj
Quantum object representation of global phase shift gate.
Examples
>>> phasegate(pi/4) Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isHerm = False Qobj data = [[ 0.70710678+0.70710678j 0.00000000+0.j] [ 0.00000000+0.j 0.70710678+0.70710678j]]
- qutip_qip.operations.hadamard_transform(N=1)[source]
Quantum object representing the N-qubit Hadamard gate.
- Returns
- qqobj
Quantum object representation of the N-qubit Hadamard gate.
- qutip_qip.operations.iswap(N=None, targets=[0, 1])[source]
Quantum object representing the iSWAP gate.
- Returns
- iswap_gateqobj
Quantum object representation of iSWAP gate
Examples
>>> iswap() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = False Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+1.j 0.+0.j] [ 0.+0.j 0.+1.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
- qutip_qip.operations.molmer_sorensen(theta, phi=0.0, N=None, targets=[0, 1])[source]
Quantum object of a Mølmer–Sørensen gate.
- Parameters
- theta: float
The duration of the interaction pulse.
- phi: float
Rotation axis. phi = 0 for XX; phi=pi for YY
- N: int
Number of qubits in the system.
- target: int
The indices of the target qubits.
- Returns
- molmer_sorensen_gate
qutip.Qobj
Quantum object representation of the Mølmer–Sørensen gate.
- molmer_sorensen_gate
- qutip_qip.operations.phasegate(theta, N=None, target=0)[source]
Returns quantum object representing the phase shift gate.
- Parameters
- thetafloat
Phase rotation angle.
- Returns
- phase_gateqobj
Quantum object representation of phase shift gate.
Examples
>>> phasegate(pi/4) Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isHerm = False Qobj data = [[ 1.00000000+0.j 0.00000000+0.j ] [ 0.00000000+0.j 0.70710678+0.70710678j]]
- qutip_qip.operations.qasmu_gate(args, N=None, target=0)[source]
QASM U-gate as defined in the OpenQASM standard.
- Parameters
- thetafloat
The argument supplied to the last RZ rotation.
- phifloat
The argument supplied to the middle RY rotation.
- gammafloat
The argument supplied to the first RZ rotation.
- Nint
Number of qubits in the system.
- targetint
The index of the target qubit.
- Returns
- qasmu_gate
qutip.Qobj
Quantum object representation of the QASM U-gate as defined in the OpenQASM standard.
- qasmu_gate
- qutip_qip.operations.qrot(theta, phi, N=None, target=0)[source]
Single qubit rotation driving by Rabi oscillation with 0 detune.
- Parameters
- phifloat
The inital phase of the rabi pulse.
- thetafloat
The duration of the rabi pulse.
- Nint
Number of qubits in the system.
- targetint
The index of the target qubit.
- Returns
- qrot_gate
qutip.Qobj
Quantum object representation of physical qubit rotation under a rabi pulse.
- qrot_gate
- qutip_qip.operations.qubit_clifford_group(N=None, target=0)[source]
Generates the Clifford group on a single qubit, using the presentation of the group given by Ross and Selinger (http://www.mathstat.dal.ca/~selinger/newsynth/).
- Parameters
- Nint or None
Number of qubits on which each operator is to be defined (default: 1).
- targetint
Index of the target qubit on which the single-qubit Clifford operators are to act.
- Yields
- opQobj
Clifford operators, represented as Qobj instances.
- qutip_qip.operations.rotation(op, phi, N=None, target=0)[source]
Single-qubit rotation for operator op with angle phi.
- Returns
- resultqobj
Quantum object for operator describing the rotation.
- qutip_qip.operations.rx(phi, N=None, target=0)[source]
Single-qubit rotation for operator sigmax with angle phi.
- Returns
- resultqobj
Quantum object for operator describing the rotation.
- qutip_qip.operations.ry(phi, N=None, target=0)[source]
Single-qubit rotation for operator sigmay with angle phi.
- Returns
- resultqobj
Quantum object for operator describing the rotation.
- qutip_qip.operations.rz(phi, N=None, target=0)[source]
Single-qubit rotation for operator sigmaz with angle phi.
- Returns
- resultqobj
Quantum object for operator describing the rotation.
- qutip_qip.operations.s_gate(N=None, target=0)[source]
Single-qubit rotation also called Phase gate or the Z90 gate.
- Returns
- result
qutip.Qobj
Quantum object for operator describing a 90 degree rotation around the z-axis.
- result
- qutip_qip.operations.snot(N=None, target=0)[source]
Quantum object representing the SNOT (Hadamard) gate.
- Returns
- snot_gateqobj
Quantum object representation of SNOT gate.
Examples
>>> snot() Quantum object: dims = [[2], [2]], shape = [2, 2], type = oper, isHerm = True Qobj data = [[ 0.70710678+0.j 0.70710678+0.j] [ 0.70710678+0.j -0.70710678+0.j]]
- qutip_qip.operations.sqrtiswap(N=None, targets=[0, 1])[source]
Quantum object representing the square root iSWAP gate.
- Returns
- sqrtiswap_gateqobj
Quantum object representation of square root iSWAP gate
Examples
>>> sqrtiswap() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = False Qobj data = [[ 1.00000000+0.j 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j] [ 0.00000000+0.j 0.70710678+0.j 0.00000000-0.70710678j 0.00000000+0.j] [ 0.00000000+0.j 0.00000000-0.70710678j 0.70710678+0.j 0.00000000+0.j] [ 0.00000000+0.j 0.00000000+0.j 0.00000000+0.j 1.00000000+0.j]]
- qutip_qip.operations.sqrtnot(N=None, target=0)[source]
Single-qubit square root NOT gate.
- Returns
- resultqobj
Quantum object for operator describing the square root NOT gate.
- qutip_qip.operations.sqrtswap(N=None, targets=[0, 1])[source]
Quantum object representing the square root SWAP gate.
- Returns
- sqrtswap_gateqobj
Quantum object representation of square root SWAP gate
- qutip_qip.operations.swap(N=None, targets=[0, 1])[source]
Quantum object representing the SWAP gate.
- Returns
- swap_gateqobj
Quantum object representation of SWAP gate
Examples
>>> swap() Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j] [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
- qutip_qip.operations.swapalpha(alpha, N=None, targets=[0, 1])[source]
Quantum object representing the SWAPalpha gate.
- Returns
- swapalpha_gateqobj
Quantum object representation of SWAPalpha gate
Examples
>>> swapalpha(alpha) Quantum object: dims = [[2, 2], [2, 2]], shape = [4, 4], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.5*(1 + exp(j*pi*alpha) 0.5*(1 - exp(j*pi*alpha) 0.+0.j] [ 0.+0.j 0.5*(1 - exp(j*pi*alpha) 0.5*(1 + exp(j*pi*alpha) 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j]]
- qutip_qip.operations.t_gate(N=None, target=0)[source]
Single-qubit rotation related to the S gate by the relationship S=T*T.
- Returns
- result
qutip.Qobj
Quantum object for operator describing a phase shift of pi/4.
- result
- qutip_qip.operations.toffoli(N=None, controls=[0, 1], target=2)[source]
Quantum object representing the Toffoli gate.
- Returns
- toff_gateqobj
Quantum object representation of Toffoli gate.
Examples
>>> toffoli() Quantum object: dims = [[2, 2, 2], [2, 2, 2]], shape = [8, 8], type = oper, isHerm = True Qobj data = [[ 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j]]
- qutip_qip.operations.x_gate(N=None, target=0)[source]
Pauli-X gate or sigmax operator.
- Returns
- result
qutip.Qobj
Quantum object for operator describing a single-qubit rotation through pi radians around the x-axis.
- result