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
statescorresponding to a givenstatespec.A
stateinrydiquleis defined by either a floating point or string value, or a tuple of such values. AStateSpeccan replace any float or string value with a list of such values. Theexpand_statespecfunction’s purpose is to convert a singlestatespecin 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
statespecis not a valid state specification.
Notes
- ..note:
This function will preserve the state type for namedtuple statespecs. So for example, passing an
A_QStatefor 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.Sensorfunctions.>>> 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]]