rydiqule.sensor_utils.expand_statespec

rydiqule.sensor_utils.expand_statespec(statespec: int | str | Tuple[float, ...] | List[int | str | Tuple[float, ...]] | Tuple[float | List[float], ...]) List[int | str | Tuple[float, ...]][source]

Returns a list of all possible states corresponding to a given statespec.

A state in rydiqule is defined by either a floating point or string value, or a tuple of such values. A StateSpec can replace any float or string value with a list of such values. The expand_statespec function’s purpose is to convert a single statespec in which some number of elements are defined as lists into a list of all the states which correspond to the state.

If the provided spec is only a single state, a 1-element list containing that state is returned.

Parameters:

statespec (StateSpec) – State specification with either zero or one element defined as a list.

Returns:

List of all states matching the provided statespec

Return type:

list of State

Raises:

RydiquleError – If the provided statespec is not a valid state specification.

Notes

..note:

This function will preserve the state type for namedtuple statespecs. So for example, passing an A_QState for example will return a list of states of the same type.

Examples

>>> ground = (0,0)
>>> excited = (1, [0,1])
>>> print(rq.expand_statespec(ground))
[(0, 0)]
>>> print(rq.expand_statespec(excited))
[(1, 0), (1, 1)]

This function has utility in allowing otherwise cubersome state definitions to be defined with variables in sensor.Sensor functions.

>>> g = (0,0)
>>> e = (1, [-1,0,1])
>>> [em1, e0, ep1] = rq.expand_statespec(e)
>>> s = rq.Sensor([g,e])
>>> cc = {(g,em1): 0.25,
...       (g,e0): 0.5,
...       (g,ep1): 0.25}
>>> s.add_coupling((g,e), detuning=1, rabi_frequency=2, coupling_coefficients=cc, label="probe")
>>> print(s.get_hamiltonian())
[[ 0.  +0.j  0.25+0.j  0.5 +0.j  0.25+0.j]
 [ 0.25-0.j -1.  +0.j  0.  +0.j  0.  +0.j]
 [ 0.5 -0.j  0.  +0.j -1.  +0.j  0.  +0.j]
 [ 0.25-0.j  0.  +0.j  0.  +0.j -1.  +0.j]]