StateRepr
- class pulser.backend.StateRepr(*, eigenstates)
Bases:
StateDefine a backend-independent quantum state representation.
Allows the user to define a quantum state with the usual dedicated class method from_state_amplitudes, which requires:
eigenstates: The basis states (e.g., (‘r’, ‘g’)).
amplitudes: A mapping between basis state combinations and complex amplitudes (e.g., {“rgr”: 1.0 / np.sqrt(2), “grg”: 1.0 / np.sqrt(2)}).
The created state, supports de/serialization methods for remote backend execution.
Examples
>>> eigenstates = ("r", "g") >>> norm_factor = 1.0 / np.sqrt(2) >>> amplitudes = {"rgr": norm_factor, "grg": norm_factor} >>> state = StateRepr.from_state_amplitudes( >>> eigenstates=eigenstates, amplitudes=amplitudes >>> )
Attributes
The eigenstates that form a qudit's eigenbasis.
The number of qudits in the state.
The dimensions (ie number of eigenstates) of a qudit.
Methods
Creates a new state of this type from another state.
Construct the state from its basis states' amplitudes.
Generates a basis state combination from its index in the state.
Infers the state measured as 1 from the eigenstates.
overlapnot implemented inStateRepr.samplenot implemented inStateRepr.Signatures
- classmethod from_state(state)
Creates a new state of this type from another state.
By default, the state is converted through its abstract representation, which is only possible if it was created via
from_state_amplitudes()and not modified afterwards. If the state is already an instance of this type, a shallow copy of it is returned instead, so it does not need to be serializable.Subclasses can override this method to support other conversions (e.g. directly from a state type they know).
- Parameters:
state (
State) – The state to convert.- Return type:
TypeVar(StateType, bound= State)- Returns:
A new state of this type, equivalent to the given one.
- Raises:
TypeError – If the state can’t be converted to this type.
- classmethod from_state_amplitudes(*, eigenstates, amplitudes)
Construct the state from its basis states’ amplitudes.
Only states constructed with this method are accepted by the remote backends.
- Parameters:
eigenstates (
Sequence[Literal['u','d','r','g','h','x'] |Literal['0','1']]) – The basis states (e.g., (‘r’, ‘g’)).amplitudes (
Mapping[str,TypeVar(ArgScalarType)]) – A mapping between basis state combinations and complex amplitudes (e.g., {“rgr”: 1.0 / np.sqrt(2), “grg”: 1.0 / np.sqrt(2)}).
- Return type:
TypeVar(StateType, bound= State)- Returns:
The state constructed from the amplitudes.
Examples
>>> eigenstates = ("r", "g") >>> norm_factor = 1.0 / np.sqrt(2) >>> # build an equal superposition of "rgr" and "grg" basis states >>> amplitudes = {"rgr": norm_factor, "grg": norm_factor} >>> config_class = your_pulser_backend.config_type >>> state_class = config_class.state_type >>> state = state_class.from_state_amplitudes( >>> eigenstates=eigenstates, amplitudes=amplitudes >>> )
- get_basis_state_from_index(index)
Generates a basis state combination from its index in the state.
Assumes a state vector representation regardless of the actual support of the state.
- Parameters:
index (
int) – The position of the state in a state vector.- Return type:
str- Returns:
The basis state combination for the desired index.
- infer_one_state()
Infers the state measured as 1 from the eigenstates.
Only works when the eigenstates form a known eigenbasis with a well-defined “one state”.
- Return type:
Literal['u','d','r','g','h','x'] |Literal['0','1']
- overlap(other, /)
overlapnot implemented inStateRepr.- Return type:
None
- sample(*, num_shots, one_state=None, p_false_pos=0.0, p_false_neg=0.0)
samplenot implemented inStateRepr.- Return type:
Counter[str]
- property eigenstates: tuple[Literal['u', 'd', 'r', 'g', 'h', 'x', '0', '1'], ...]
The eigenstates that form a qudit’s eigenbasis.
The order of the states should match the order in a numerical (ie state vector or density matrix) representation. For example, with eigenstates (“a”, “b”, …), “a” will be associated to eigenvector (1, 0, …), “b” to (0, 1, …) and so on.
- property n_qudits: int
The number of qudits in the state.
- property qudit_dim: int
The dimensions (ie number of eigenstates) of a qudit.