Qubits for quantum computing.
Todo: * Finish implementing measurement logic. This should include POVM. * Update docstrings. * Update tests.
A multi-qubit ket in the computational (z) basis.
We use the normal convention that the least significant qubit is on the right, so |00001> has a 1 in the least significant qubit.
Parameters : | values : list, str
|
---|
Examples
Create a qubit in a couple of different ways and look at their attributes:
>>> from sympy.physics.quantum.qubit import Qubit
>>> Qubit(0,0,0)
|000>
>>> q = Qubit('0101')
>>> q
|0101>
>>> q.nqubits
4
>>> len(q)
4
>>> q.dimension
4
>>> q.qubit_values
(0, 1, 0, 1)
We can flip the value of an individual qubit:
>>> q.flip(1)
|0111>
We can take the dagger of a Qubit to get a bra:
>>> from sympy.physics.quantum.dagger import Dagger
>>> Dagger(q)
<0101|
>>> type(Dagger(q))
<class 'sympy.physics.quantum.qubit.QubitBra'>
Inner products work as expected:
>>> ip = Dagger(q)*q
>>> ip
<0101|0101>
>>> ip.doit()
1
A multi-qubit bra in the computational (z) basis.
We use the normal convention that the least significant qubit is on the right, so |00001> has a 1 in the least significant qubit.
Parameters : | values : list, str
|
---|
See also
A qubit ket that store integers as binary numbers in qubit values.
The differences between this class and Qubit are:
Parameters : | values : int, tuple
|
---|
Examples
Create a qubit for the integer 5:
>>> from sympy.physics.quantum.qubit import IntQubit
>>> from sympy.physics.quantum.qubit import Qubit
>>> q = IntQubit(5)
>>> q
|5>
We can also create an IntQubit by passing a Qubit instance.
>>> q = IntQubit(Qubit('101'))
>>> q
|5>
>>> q.as_int()
5
>>> q.nqubits
3
>>> q.qubit_values
(1, 0, 1)
We can go back to the regular qubit form.
>>> Qubit(q)
|101>
A qubit bra that store integers as binary numbers in qubit values.
Coverts an Add/Mul of Qubit objects into it’s matrix representation
This function is the inverse of matrix_to_qubit and is a shorthand for represent(qubit).
Convert from the matrix repr. to a sum of Qubit objects.
Parameters : | matrix : Matrix, numpy.matrix, scipy.sparse
|
---|
Examples
Represent a state and then go back to its qubit form:
>>> from sympy.physics.quantum.qubit import matrix_to_qubit, Qubit
>>> from sympy.physics.quantum.gate import Z
>>> from sympy.physics.quantum.represent import represent
>>> q = Qubit('01')
>>> matrix_to_qubit(represent(q))
|01>
Works by finding the eigenvectors and eigenvalues of the matrix. We know we can decompose rho by doing: sum(EigenVal*|Eigenvect><Eigenvect|)
Perform an ensemble measurement of all qubits.
Parameters : | qubit : Qubit, Add
format : str
|
---|---|
Returns : | result : list
|
Examples
>>> from sympy.physics.quantum.qubit import Qubit, measure_all
>>> from sympy.physics.quantum.gate import H, X, Y, Z
>>> from sympy.physics.quantum.qapply import qapply
>>> c = H(0)*H(1)*Qubit('00')
>>> c
H(0)*H(1)*|00>
>>> q = qapply(c)
>>> measure_all(q)
[(|00>, 1/4), (|01>, 1/4), (|10>, 1/4), (|11>, 1/4)]
Perform a partial ensemble measure on the specifed qubits.
Parameters : | qubits : Qubit
bits : tuple
format : str
|
---|---|
Returns : | result : list
|
Examples
>>> from sympy.physics.quantum.qubit import Qubit, measure_partial
>>> from sympy.physics.quantum.gate import H, X, Y, Z
>>> from sympy.physics.quantum.qapply import qapply
>>> c = H(0)*H(1)*Qubit('00')
>>> c
H(0)*H(1)*|00>
>>> q = qapply(c)
>>> measure_partial(q, (0,))
[(sqrt(2)*|00>/2 + sqrt(2)*|10>/2, 1/2), (sqrt(2)*|01>/2 + sqrt(2)*|11>/2, 1/2)]
Perform a partial oneshot measurement on the specified qubits.
A oneshot measurement is equivalent to performing a measurement on a quantum system. This type of measurement does not return the probabilities like an ensemble measurement does, but rather returns one of the possible resulting states. The exact state that is returned is determined by picking a state randomly according to the ensemble probabilities.
Parameters : | qubits : Qubit
bits : tuple
format : str
|
---|---|
Returns : | result : Qubit
|
Perform a oneshot ensemble measurement on all qubits.
A oneshot measurement is equivalent to performing a measurement on a quantum system. This type of measurement does not return the probabilities like an ensemble measurement does, but rather returns one of the possible resulting states. The exact state that is returned is determined by picking a state randomly according to the ensemble probabilities.
Parameters : | qubits : Qubit
format : str
|
---|---|
Returns : | result : Qubit
|