This package defines some tools to work with in Python code. These can be used to create and manipulate quantum states, or to calculate expectation values.
This module provides an implementation for state vectors and density operators. These two classes are not direct wrappings of their C++QED counterparts to make them behave more pythonic. In fact, both these classes are derived from numpy.ndarray.
A class representing a quantum mechanical density operator. quantumdata::DensityOperator is automatically converted to this, but it is not a one to one wrapper.
Return a DensityOperator where the given subsystems are Fourier transformed. This is the transformation position space -> momentum space.
Parameters: | subsystems – (optional) Sequence of ints, subsystems over which the fft is done. (Default is all) |
---|
Return a DensityOperator where the given subsystems are inversely Fourier transformed. This is the transformation momentum space -> position space.
Parameters: | subsystems – (optional) Sequence of ints, subsystems over which the ifft is done. (Default is all) |
---|
This is the base class for StateVector and DensityOperator. It inherits from numpy.ndarray.
Parameters: |
|
---|
Any other argument that a numpy array takes. E.g. copy=False can be used so that the QuantumState shares the data storage with the given numpy array.
Most useful is maybe the tensor product ‘**’ which lets you easily calculate state vectors for combined systems.
A class representing a quantum mechanical state. quantumdata::StateVector is automatically converted to this, but it is not a one to one wrapper.
>>> sv = StateVector((1, 3, 7, 2), time=0.2, norm=True)
>>> sv = StateVector(numpy.arange(12).reshape(3,4))
>>> print sv
StateVector(3 x 4)
>>> print repr(sv)
StateVector([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
Parameters: |
|
---|
Most useful is maybe the tensor product which lets you easily calculate state vectors for combined systems:
>>> sv1 = StateVector((1,2,3))
>>> sv2 = StateVector((3,4,0), norm=True)
>>> sv = sv1 ** sv2
>>> print sv
StateVector(3 x 3)
>>> print repr(sv)
StateVector([[ 0.6, 0.8, 0. ],
[ 1.2, 1.6, 0. ],
[ 1.8, 2.4, 0. ]])
The tensor product is abbreviated by the “**” operator.
Calculate the expectation value for the given diagonal operator.
>>> a = numpy.arange(4)
>>> print a
array([ 0., 1., 2., 3.])
>>> sv = StateVector((1,2,1,4), norm=True)
>>> print sv.diagexpvalue(a)
2.45454545455
Parameters: |
|
---|
Expectation values for combined systems are calculated in the following way (Assuming the operator only acts on first subsystem):
Other than the general expvalue method diagexpvalue only works for diagonal operators and only needs the diagonal elements of the matrix representation.
Calculate the dyadic product with itself.
Returns: | The DensityOperator . |
---|
Calculate the expectation value of the given operator.
>>> a = numpy.diag(numpy.ones(3), -1)
>>> print a
array([[ 0., 0., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.]])
>>> sv = StateVector((1,2,1,2), norm=True)
>>> print sv.expvalue(a)
0.6
Parameters: |
|
---|
Expectation values for combined systems are calculated in the following way (Assuming the operator only acts on first subsystem):
The second sum is exactly what reducesquare does while the first expression is the matrix representation of the given operator in the same basis as the StateVector.
Return a StateVector where the given axes are Fourier transformed. This is the transformation position space -> momentum space.
>>> sv = StateVector((0,1,1.7,2,1.7,1,0), norm=True)
>>> print sv.fft()
StateVector(7)
Parameters: | axis – (optional) Sequence of ints, axes over which the fft is done. (Default is all) |
---|
Return a StateVector where the given axes are inversely Fourier transformed. This is the transformation momentum space -> position space.
See StateVector.fft for details.
Calculate the norm of the StateVector.
>>> sv = StateVector((1,2,3,4,5), norm=True)
>>> print sv.norm()
1.0
Return a normalized StateVector.
>>> sv = StateVector((1,2,1,3,1))
>>> print sv.norm()
4.0
>>> nsv = sv.normalize()
>>> print nsv.norm()
1.0
Return the outer product between this and the given StateVector.
>>> sv = StateVector((0,1,2), norm=True)
>>> print repr(sv.outer(StateVector((3,4), norm=True)))
StateVector([[ 0. , 0. ],
[ 0.26832816, 0.35777088],
[ 0.53665631, 0.71554175]])
>>> print sv.outer((3,4)) # Not normalized!
StateVector([[ 0. , 0. ],
[ 1.34164079, 1.78885438],
[ 2.68328157, 3.57770876]])
Parameters: | array – Some kind of array (E.g. StateVector, numpy.array, list, ...). |
---|
As abbreviation sv1**sv2 can be written instead of sv1.outer(sv2).
Return a StateVector where the given indices are reduced.
>>> rsv = sv.reduce(1)
>>> rsv = sv.reduce((1,2))
Parameters: |
|
---|
Reducing means nothing else then summing up over all given indices. E.g. a StateVector of rank 4 can be reduced to the first two indices:
>>> sv1 = StateVector((1,2), norm=True)
>>> sv2 = StateVector((1,2,3), norm=True)
>>> sv3 = StateVector((1,2,3,4,5), norm=True)
>>> sv4 = StateVector((1,2,3,4,5,6), norm=True)
>>> sv = sv1**sv2**sv3**sv4
>>> print sv
StateVector(2 x 3 x 5 x 6)
>>> print sv.reduce((2,3))
StateVector(2 x 3)
This is mathematically equivalent to:
Reducing is an easy way to find out how subspaces of a high rank state vectors behave. Don’t use reduced StateVectors for calculating expectation values - this will most likely give wrong answers!
Calculate the reduced Psi-square tensor.
>>> sv1 = StateVector((0,1,2,1,0), norm=True)
>>> sv2 = StateVector((1,0,1), norm=True)
>>> sv = sv1**sv2
>>> sqtensor = sv.reducesquare(1)
Parameters: | indices – An integer or a list of integers specifying over which subsystems should be summed up. |
---|
This method calculates the following quantity (simplified for rank 2 state vectors):
Where is the reduced index.
This quantity is useful to calculate expectation values in the corresponding subspaces.
A class holding StateVectors for different points of time.
Parameters: |
|
---|
Most methods are simple mapped to all single StateVectors. For more documentation regarding these methods look into the docstrings of the corresponding StateVector methods.
Calculate the expectation value of the diagonal operator for all SVs.
Returns: | An expvalues.ExpectationValuesTrajectory instance. |
---|
See also: StateVector.diagexpvalue
Calculate the expectation value of the operator for all StateVectors.
Returns: | An expvalues.ExpectationValuesTrajectory instance. |
---|
See also: StateVector.expvalue
Return a StateVectorTrajectory whith Fourier transformed StateVectors.
See also: StateVector.fft
Apply the given function to every single StateVector.
>>> norm = svt.map(lambda sv:sv.norm())
Paramter func: | Function that takes a StateVector as argument. |
---|---|
Parameters: | svt (bool) – (optional) If svt is True, the return value will be an instance of StateVectorTrajectory. |
Return a list of norms for every single StateVector.
See also: StateVector.norm
Return a StateVectorTrajectory where all StateVectors are normalized.
See also: StateVector.normalize
Return a StateVectorTrajectory where all StateVectors are reduced.
See also: StateVector.reduce
Adjust the dimensionality of a 1D array.
Return the norm of the array.
Return a normalized array.
This module provides convenient methods for creating initial conditions.
Generate a coherent StateVector in the Fock space.
>>> sv = coherent(alpha=2, N=20)
>>> print sv
StateVector(20)
Parameters: |
|
---|---|
Returns sv: |
The coherent state is given by the formula:
Calculation is done using the recursive formula:
Generate a Fock space basis vector.
>>> sv = fock(dim=8, i=4)
>>> print sv
StateVector(8)
Parameters: | |
---|---|
Returns sv: |
Generate a StateVector with a normal distribution.
>>> sv = gaussian(x0=0.3, k0=4, sigma=0.6, fin=7)
>>> print sv
StateVector(128)
Parameters: |
|
---|---|
Returns sv: | A quantumstate.StateVector representing this gaussian wave packet in the k-space. |
The generated StateVector is normalized and given in the k-space. It is the discretized and Fourier transformed of the following expression:
The discretization is given by:
Generate a momentum eigenstate with momentum p in a space with finesse fin.
>>> sv = momentum_eigen(0, fin=4)
>>> print sv
StateVector(16)
Parameters: | |
---|---|
Returns sv: |