An implementation of gates that act on qubits.
Gates are unitary operators that act on the space of qubits.
Medium Term Todo:
Non-controlled unitary gate operator that acts on qubits.
This is a general abstract gate that needs to be subclassed to do anything useful.
Parameters: | label : tuple, int
|
---|
The matrix rep. of the target part of the gate.
Parameters: | format : str
|
---|
The minimum number of qubits this gate needs to act on.
The total number of qubits this gate acts on.
For controlled gate subclasses this includes both target and control qubits, so that, for examples the CNOT gate acts on 2 qubits.
A tuple of target qubits.
A general unitary gate with control qubits.
A general control gate applies a target gate to a set of targets if all of the control qubits have a particular values (set by CGate.control_value).
Parameters: | label : tuple
|
---|
A tuple of control qubits.
Decompose the controlled gate into CNOT and single qubits gates.
Return True/False to indicate if the controls are satisfied.
The non-controlled gate that will be applied to the targets.
The minimum number of qubits this gate needs to act on.
The total number of qubits this gate acts on.
For controlled gate subclasses this includes both target and control qubits, so that, for examples the CNOT gate acts on 2 qubits.
Plot the controlled gate. If simplify_cgate is true, simplify C-X and C-Z gates into their more familiar forms.
A tuple of target qubits.
General gate specified by a set of targets and a target matrix.
Parameters: | label : tuple
|
---|
The matrix rep. of the target part of the gate.
Parameters: | format : str
|
---|
A tuple of target qubits.
A single qubit unitary gate base class.
A two qubit unitary gate base class.
The single qubit identity gate.
Parameters: | target : int
|
---|
The single qubit Hadamard gate.
Parameters: | target : int
|
---|
Examples
>>> from sympy import sqrt
>>> from sympy.physics.quantum.qubit import Qubit
>>> from sympy.physics.quantum.gate import HadamardGate
>>> from sympy.physics.quantum.qapply import qapply
>>> qapply(HadamardGate(0)*Qubit('1'))
sqrt(2)*|0>/2 - sqrt(2)*|1>/2
>>> # Hadamard on bell state, applied on 2 qubits.
>>> psi = 1/sqrt(2)*(Qubit('00')+Qubit('11'))
>>> qapply(HadamardGate(0)*HadamardGate(1)*psi)
sqrt(2)*|00>/2 + sqrt(2)*|11>/2
The single qubit X, or NOT, gate.
Parameters: | target : int
|
---|
The single qubit Y gate.
Parameters: | target : int
|
---|
The single qubit Z gate.
Parameters: | target : int
|
---|
The single qubit pi/8 gate.
This gate rotates the phase of the state by pi/4 if the state is |1> and does nothing if the state is |0>.
Parameters: | target : int
|
---|
The single qubit phase, or S, gate.
This gate rotates the phase of the state by pi/2 if the state is |1> and does nothing if the state is |0>.
Parameters: | target : int
|
---|
Two qubit SWAP gate.
This gate swap the values of the two qubits.
Parameters: | label : tuple
|
---|
Decompose the SWAP gate into CNOT gates.
Two qubit controlled-NOT.
This gate performs the NOT or X gate on the target qubit if the control qubits all have the value 1.
Parameters: | label : tuple
|
---|
Examples
>>> from sympy.physics.quantum.gate import CNOT
>>> from sympy.physics.quantum.qapply import qapply
>>> from sympy.physics.quantum.qubit import Qubit
>>> c = CNOT(1,0)
>>> qapply(c*Qubit('10')) # note that qubits are indexed from right to left
|11>
A tuple of control qubits.
The non-controlled gate that will be applied to the targets.
The minimum number of qubits this gate needs to act on.
A tuple of target qubits.
alias of HadamardGate
Set flag controlling normalization of Hadamard gates by 1/sqrt(2).
This is a global setting that can be used to simplify the look of various expressions, by leaving off the leading 1/sqrt(2) of the Hadamard gate.
Parameters: | normalize : bool
|
---|
Sorts the gates while keeping track of commutation relations
This function uses a bubble sort to rearrange the order of gate application. Keeps track of Quantum computations special commutation relations (e.g. things that apply to the same Qubit do not commute with each other)
circuit is the Mul of gates that are to be sorted.
Simplifies gates symbolically
It first sorts gates using gate_sort. It then applies basic simplification rules to the circuit, e.g., XGate**2 = Identity
Return a random circuit of ngates and nqubits.
This uses an equally weighted sample of (X, Y, Z, S, T, H, CNOT, SWAP) gates.
Parameters: | ngates : int
nqubits : int
gate_space : tuple
|
---|
Version of CGate that allows gate simplifications. I.e. cnot looks like an oplus, cphase has dots, etc.