qutip_qip.operations

Operations on quantum circuits.

Classes

Gate(name[, targets, controls, arg_value, …])

Representation of a quantum gate, with its required parametrs, and target and control qubits.

Functions

berkeley([N, targets])

Quantum object representing the Berkeley gate.

cnot([N, control, target])

Quantum object representing the CNOT gate.

controlled_gate(U[, N, control, target, …])

Create an N-qubit controlled gate from a single-qubit gate U with the given control and target qubits.

cphase(theta[, N, control, target])

Returns quantum object representing the controlled phase shift gate.

cs_gate([N, control, target])

Controlled S gate.

csign([N, control, target])

Quantum object representing the CSIGN gate.

ct_gate([N, control, target])

Controlled T gate.

cy_gate([N, control, target])

Controlled Y gate.

cz_gate([N, control, target])

Controlled Z gate.

expand_operator(oper, N, targets[, dims, …])

Expand a qubits operator to one that acts on a N-qubit system.

fredkin([N, control, targets])

Quantum object representing the Fredkin gate.

gate_expand_1toN(U, N, target)

Create a Qobj representing a one-qubit gate that act on a system with N qubits.

gate_expand_2toN(U, N[, control, target, …])

Create a Qobj representing a two-qubit gate that act on a system with N qubits.

gate_expand_3toN(U, N[, controls, target])

Create a Qobj representing a three-qubit gate that act on a system with N qubits.

gate_sequence_product(U_list[, …])

Calculate the overall unitary matrix for a given list of unitary operations.

globalphase(theta[, N])

Returns quantum object representing the global phase shift gate.

hadamard_transform([N])

Quantum object representing the N-qubit Hadamard gate.

iswap([N, targets])

Quantum object representing the iSWAP gate.

molmer_sorensen(theta[, N, targets])

Quantum object of a Mølmer–Sørensen gate.

phasegate(theta[, N, target])

Returns quantum object representing the phase shift gate.

qasmu_gate(args[, N, target])

QASM U-gate as defined in the OpenQASM standard.

qrot(theta, phi[, N, target])

Single qubit rotation driving by Rabi oscillation with 0 detune.

qubit_clifford_group([N, target])

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/).

rotation(op, phi[, N, target])

Single-qubit rotation for operator op with angle phi.

rx(phi[, N, target])

Single-qubit rotation for operator sigmax with angle phi.

ry(phi[, N, target])

Single-qubit rotation for operator sigmay with angle phi.

rz(phi[, N, target])

Single-qubit rotation for operator sigmaz with angle phi.

s_gate([N, target])

Single-qubit rotation also called Phase gate or the Z90 gate.

snot([N, target])

Quantum object representing the SNOT (Hadamard) gate.

sqrtiswap([N, targets])

Quantum object representing the square root iSWAP gate.

sqrtnot([N, target])

Single-qubit square root NOT gate.

sqrtswap([N, targets])

Quantum object representing the square root SWAP gate.

swap([N, targets])

Quantum object representing the SWAP gate.

swapalpha(alpha[, N, targets])

Quantum object representing the SWAPalpha gate.

t_gate([N, target])

Single-qubit rotation related to the S gate by the relationship S=T*T.

toffoli([N, controls, target])

Quantum object representing the Toffoli gate.

x_gate([N, target])

Pauli-X gate or sigmax operator.

y_gate([N, target])

Pauli-Y gate or sigmay operator.

z_gate([N, target])

Pauli-Z gate or sigmaz operator.

class qutip_qip.operations.Gate(name, targets=None, controls=None, arg_value=None, arg_label=None, classical_controls=None, control_value=None)[source]

Bases: object

Representation of a quantum gate, with its required parametrs, and target and control qubits.

Parameters
namestring

Gate name.

targetslist or int

Gate targets.

controlslist or int

Gate controls.

arg_valuefloat

Argument value(phi).

arg_labelstring

Label for gate representation.

classical_controlsint or list of int, optional

indices of classical bits to control gate on.

control_valueint, optional

value of classical bits to control on, the classical controls are interpreted as an integer with lowest bit being the first one. If not specified, then the value is interpreted to be 2 ** len(classical_controls) - 1 (i.e. all classical controls are 1).

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
qobjqutip.Qobj

The compact gate operator as a unitary matrix.

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
qobjqutip.Qobj

The compact gate operator as a unitary matrix.

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, N=2, control=0, target=1, control_value=1)[source]

Create an N-qubit controlled gate from a single-qubit gate U with the given control and target qubits.

Parameters
UQobj

Arbitrary single-qubit gate.

Ninteger

The number of qubits in the target space.

controlinteger

The index of the first control qubit.

targetinteger

The index of the target qubit.

control_valueinteger (1)

The state of the control qubit that activates the gate 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
resultqutip.Qobj

Quantum object for operator describing the rotation.

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
resultqutip.Qobj

Quantum object for operator describing the rotation.

qutip_qip.operations.cy_gate(N=None, control=0, target=1)[source]

Controlled Y gate.

Returns
resultqutip.Qobj

Quantum object for operator describing the rotation.

qutip_qip.operations.cz_gate(N=None, control=0, target=1)[source]

Controlled Z gate.

Returns
resultqutip.Qobj

Quantum object for operator describing the rotation.

qutip_qip.operations.expand_operator(oper, N, targets, dims=None, cyclic_permutation=False)[source]

Expand a qubits operator to one that acts on a N-qubit system.

Parameters
operqutip.Qobj

An operator acts on qubits, the type of the qutip.Qobj has to be an operator and the dimension matches the tensored qubit Hilbert space e.g. dims = [[2, 2, 2], [2, 2, 2]]

Nint

The number of qubits in the system.

targetsint or list of int

The indices of qubits that are acted on.

dimslist, optional

A list of integer for the dimension of each composite system. E.g [2, 2, 2, 2, 2] for 5 qubits system. If None, qubits system will be the default option.

cyclic_permutationboolean, optional

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.

Returns
expanded_operqutip.Qobj

The expanded qubits operator acting on a system with N qubits.

Notes

This is equivalent to gate_expand_1toN, gate_expand_2toN, gate_expand_3toN in qutip_qip.gate.py, but works for any dimension.

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_expand_1toN(U, N, target)[source]

Create a Qobj representing a one-qubit gate that act on a system with N qubits.

Parameters
UQobj

The one-qubit gate

Ninteger

The number of qubits in the target space.

targetinteger

The index of the target qubit.

Returns
gateqobj

Quantum object representation of N-qubit gate.

qutip_qip.operations.gate_expand_2toN(U, N, control=None, target=None, targets=None)[source]

Create a Qobj representing a two-qubit gate that act on a system with N qubits.

Parameters
UQobj

The two-qubit gate

Ninteger

The number of qubits in the target space.

controlinteger

The index of the control qubit.

targetinteger

The index of the target qubit.

targetslist

List of target qubits.

Returns
gateqobj

Quantum object representation of N-qubit gate.

qutip_qip.operations.gate_expand_3toN(U, N, controls=[0, 1], target=2)[source]

Create a Qobj representing a three-qubit gate that act on a system with N qubits.

Parameters
UQobj

The three-qubit gate

Ninteger

The number of qubits in the target space.

controlslist

The list of the control qubits.

targetinteger

The index of the target qubit.

Returns
gateqobj

Quantum object representation of N-qubit gate.

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, N=None, targets=[0, 1])[source]

Quantum object of a Mølmer–Sørensen gate.

Parameters
theta: float

The duration of the interaction pulse.

N: int

Number of qubits in the system.

target: int

The indices of the target qubits.

Returns
molmer_sorensen_gatequtip.Qobj

Quantum object representation of the Mølmer–Sørensen 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_gatequtip.Qobj

Quantum object representation of the QASM U-gate as defined in the OpenQASM standard.

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_gatequtip.Qobj

Quantum object representation of physical qubit rotation under a rabi pulse.

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
resultqutip.Qobj

Quantum object for operator describing a 90 degree rotation around the z-axis.

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
resultqutip.Qobj

Quantum object for operator describing a phase shift of pi/4.

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
resultqutip.Qobj

Quantum object for operator describing a single-qubit rotation through pi radians around the x-axis.

qutip_qip.operations.y_gate(N=None, target=0)[source]

Pauli-Y gate or sigmay operator.

Returns
resultqutip.Qobj

Quantum object for operator describing a single-qubit rotation through pi radians around the y-axis.

qutip_qip.operations.z_gate(N=None, target=0)[source]

Pauli-Z gate or sigmaz operator.

Returns
resultqutip.Qobj

Quantum object for operator describing a single-qubit rotation through pi radians around the z-axis.