pygsti.baseobjs.statespace
¶
Defines OrderedDictderived classes used to store specific pyGSTi objects
Module Contents¶
Classes¶
Base class for defining a state space (Hilbert or HilbertSchmidt space). 

A state space consisting of N qubits. 

A customizable definition of a state space. 
Functions¶
Create a state space for a given superoperator dimension. 


Create a state space for a given unitary operator dimension. 

Create a state space for a given number of qubits. 
 class pygsti.baseobjs.statespace.StateSpace¶
Bases:
pygsti.baseobjs.nicelyserializable.NicelySerializable
Base class for defining a state space (Hilbert or HilbertSchmidt space).
This base class just sets the API for a “state space” in pyGSTi, accessed as the direct sum of one or more tensor products of Hilbert spaces.
 classmethod cast(cls, obj)¶
Casts obj into a
StateSpace
object if possible.If obj is already of this type, it is simply returned without modification.
 Parameters
obj (StateSpace or int or list) – Either an alreadybuilt state space object or an integer specifying the number of qubits, or a list of labels as would be provided to the first argument of :method:`ExplicitStateSpace.__init__`.
 Returns
StateSpace
 property udim(self)¶
Integer Hilbert (unitary operator) space dimension of this quantum state space.
Raises an error if this space is not a quantum state space.
 property dim(self)¶
Integer HilbertSchmidt (superoperator) or classical dimension of this state space.
 property num_qubits(self)¶
The number of qubits in this quantum state space.
Raises a ValueError if this state space doesn’t consist entirely of qubits.
 property num_tensor_product_blocks(self)¶
The number of tensorproduct blocks which are directsummed to get the final state space.
 Returns
int
 property tensor_product_blocks_labels(self)¶
The labels for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_dimensions(self)¶
The superoperator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_udimensions(self)¶
The unitary operator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_types(self)¶
The type (quantum vs classical) of all the tensorproduct blocks.
 Returns
tuple of tuples
 abstract label_dimension(self, label)¶
The superoperator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 abstract label_udimension(self, label)¶
The unitary operator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 abstract label_tensor_product_block_index(self, label)¶
The index of the tensor product block containing the given label.
 Parameters
label (str or int) – The label whose index should be retrieved.
 Returns
int
 abstract label_type(self, label)¶
The type (quantum or classical) of the given label (from any tensor product block).
 Parameters
label (str or int) – The label whose type should be retrieved.
 Returns
str
 tensor_product_block_labels(self, i_tpb)¶
The labels for the iTBPth tensorproduct block.
 Parameters
i_tpb (int) – Tensorproduct block index.
 Returns
tuple
 tensor_product_block_dimensions(self, i_tpb)¶
The superoperator dimensions for the factors in the iTBPth tensorproduct block.
 Parameters
i_tpb (int) – Tensorproduct block index.
 Returns
tuple
 tensor_product_block_udimensions(self, i_tpb)¶
The unitaryoperator dimensions for the factors in the iTBPth tensorproduct block.
 Parameters
i_tpb (int) – Tensorproduct block index.
 Returns
tuple
 copy(self)¶
Return a copy of this StateSpace.
 Returns
StateSpace
 is_compatible_with(self, other_state_space)¶
Whether another state space is compatible with this one.
Two state spaces are considered “compatible” when their overall dimensions agree (even if their tensor product block structure and labels do not). (This checks whether the Hilbert spaces are isomorphic.)
 Parameters
other_state_space (StateSpace) – The state space to check compatibility with.
 Returns
bool
 property is_entirely_qubits(self)¶
Whether this state space is just the tensor product of qubit subspaces.
 Returns
bool
 is_entire_space(self, labels)¶
True if this state space is a single tensor product block with (exactly, in order) the given set of labels.
 Parameters
labels (iterable) – the labels to test.
 Returns
bool
 contains_labels(self, labels)¶
True if this state space contains all of a given set of labels.
 Parameters
labels (iterable) – the labels to test.
 Returns
bool
 contains_label(self, label)¶
True if this state space contains a given label.
 Parameters
label (str or int) – the label to test for.
 Returns
bool
 property common_dimension(self)¶
Returns the common superop dimension of all the labels in this space.
If not all the labels in this space have the same dimension, then None is returned to indicate this.
This property is useful when working with stencils, where operations are created for a “stencil space” that is not exactly a subspace of a StateSpace space but will be mapped to one in the future.
 Returns
int or None
 property common_udimension(self)¶
Returns the common unitaryop dimension of all the labels in this space.
If not all the labels in this space have the same dimension, then None is returned to indicate this.
This property is useful when working with stencils, where operations are created for a “stencil space” that is not exactly a subspace of a StateSpace space but will be mapped to one in the future.
 Returns
int or None
 create_subspace(self, labels)¶
Create a subStateSpace object from a set of existing labels.
 Parameters
labels (iterable) – The labels to include in the returned state space.
 Returns
StateSpace
 intersection(self, other_state_space)¶
Create a state space whose labels are the intersection of the labels of this space and one other.
Dimensions associated with the labels are preserved, as is the ordering of tensor product blocks. If the two spaces have the same label, but their dimensions or indices do not agree, an error is raised.
 Parameters
other_state_space (StateSpace) – The other state space.
 Returns
StateSpace
 union(self, other_state_space)¶
Create a state space whose labels are the union of the labels of this space and one other.
Dimensions associated with the labels are preserved, as is the tensor product block index. If the two spaces have the same label, but their dimensions or indices do not agree, an error is raised.
 Parameters
other_state_space (StateSpace) – The other state space.
 Returns
StateSpace
 create_stencil_subspace(self, labels)¶
Create a template subStateSpace object from a set of potentially stenciltype labels.
That is, the elements of labels don’t need to actually exist within this state space – they may be stencil labels that will resolve to a label in this state space later on.
 Parameters
labels (iterable) – The labels to include in the returned state space.
 Returns
StateSpace
 __repr__(self)¶
Return repr(self).
 __hash__(self)¶
Return hash(self).
 __eq__(self, other_statespace)¶
Return self==value.
 class pygsti.baseobjs.statespace.QubitSpace(nqubits_or_labels)¶
Bases:
StateSpace
A state space consisting of N qubits.
 _to_nice_serialization(self)¶
 classmethod _from_nice_serialization(cls, state)¶
 property udim(self)¶
Integer Hilbert (unitary operator) space dimension of this quantum state space.
 property dim(self)¶
Integer HilbertSchmidt (superoperator) or classical dimension of this state space.
 property num_qubits(self)¶
The number of qubits in this quantum state space.
 property num_tensor_product_blocks(self)¶
Get the number of tensorproduct blocks which are directsummed to get the final state space.
 Returns
int
 property tensor_product_blocks_labels(self)¶
Get the labels for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_dimensions(self)¶
Get the superoperator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_udimensions(self)¶
Get the unitary operator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_types(self)¶
Get the type (quantum vs classical) of all the tensorproduct blocks.
 Returns
tuple of tuples
 label_dimension(self, label)¶
The superoperator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 label_udimension(self, label)¶
The unitary operator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 label_tensor_product_block_index(self, label)¶
The index of the tensor product block containing the given label.
 Parameters
label (str or int) – The label whose index should be retrieved.
 Returns
int
 label_type(self, label)¶
The type (quantum or classical) of the given label (from any tensor product block).
 Parameters
label (str or int) – The label whose type should be retrieved.
 Returns
str
 __str__(self)¶
Return str(self).
 class pygsti.baseobjs.statespace.ExplicitStateSpace(label_list, udims=None, types=None)¶
Bases:
StateSpace
A customizable definition of a state space.
An ExplicitStateSpace object describes, using string/int labels, how an entire Hilbert state space is decomposed into the direct sum of terms which themselves are tensor products of smaller (typically qubitsized) Hilbert spaces.
 Parameters
label_list (str or int or iterable) –
Most generally, this can be a list of tuples, where each tuple contains the statespace labels (which can be strings or integers) for a single “tensor product block” formed by taking the tensor product of the spaces asociated with the labels. The full state space is the direct sum of all the tensor product blocks. E.g. [(‘Q0’,’Q1’), (‘Q2’,)].
If just an iterable of labels is given, e.g. (‘Q0’,’Q1’), it is assumed to specify the first and only tensor product block.
If a single state space label is given, e.g. ‘Q2’, then it is assumed to completely specify the first and only tensor product block.
udims (int or iterable, optional) –
The dimension of each state space label as an integer, tuple of integers, or list or tuples of integers to match the structure of label_list (i.e., if label_list=(‘Q0’,’Q1’) then dims should be a tuple of 2 integers). Values specify unitary evolution statespace dimensions, i.e. 2 for a qubit, 3 for a qutrit, etc. If None, then the dimensions are inferred, if possible, from the following naming rules:
if the label starts with ‘L’, udim=1 (a single Level)
if the label starts with ‘Q’ OR is an int, udim=2 (a Qubit)
if the label starts with ‘T’, udim=3 (a quTrit)
types (str or iterable, optional) – A list of label types, either ‘Q’ or ‘C’ for “quantum” and “classical” respectively, indicating the type of statespace associated with each label. Like dims, types must match the structure of label_list. A quantum state space of dimension d is a dbyd density matrix, whereas a classical state space of dimension d is a vector of d probabilities. If None, then all labels are assumed to be quantum.
 _to_nice_serialization(self)¶
 classmethod _from_nice_serialization(cls, state)¶
 property udim(self)¶
Integer Hilbert (unitary operator) space dimension of this quantum state space.
Raises an error if this space is not a quantum state space.
 property dim(self)¶
Integer HilbertSchmidt (superoperator) or classical dimension of this state space.
 property num_qubits(self)¶
The number of qubits in this quantum state space.
Raises a ValueError if this state space doesn’t consist entirely of qubits.
 property num_tensor_product_blocks(self)¶
The number of tensorproduct blocks which are directsummed to get the final state space.
 Returns
int
 property tensor_product_blocks_labels(self)¶
The labels for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_dimensions(self)¶
The superoperator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_udimensions(self)¶
The unitary operator dimensions for all the tensorproduct blocks.
 Returns
tuple of tuples
 property tensor_product_blocks_types(self)¶
The type (quantum vs classical) of all the tensorproduct blocks.
 Returns
tuple of tuples
 label_dimension(self, label)¶
The superoperator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 label_udimension(self, label)¶
The unitary operator dimension of the given label (from any tensor product block)
 Parameters
label (str or int) – The label whose dimension should be retrieved.
 Returns
int
 label_tensor_product_block_index(self, label)¶
The index of the tensor product block containing the given label.
 Parameters
label (str or int) – The label whose index should be retrieved.
 Returns
int
 label_type(self, label)¶
The type (quantum or classical) of the given label (from any tensor product block).
 Parameters
label (str or int) – The label whose type should be retrieved.
 Returns
str
 __str__(self)¶
Return str(self).
 pygsti.baseobjs.statespace.default_space_for_dim(dim)¶
Create a state space for a given superoperator dimension.
 Parameters
dim (int) – The dimension.
 Returns
StateSpace
 pygsti.baseobjs.statespace.default_space_for_udim(udim)¶
Create a state space for a given unitary operator dimension.
 Parameters
dim (int) – The dimension.
 Returns
StateSpace
 pygsti.baseobjs.statespace.default_space_for_num_qubits(num_qubits)¶
Create a state space for a given number of qubits.
 Parameters
num_qubits (int) – The number of qubits.
 Returns
QubitStateSpace