q1ss.ap.base

Abstract base class for ordered affine partitions.

AP

class AP(subsp_dim, ambient_dim)[source]

Bases: ABC

Abstract base class for ordered balanced affine partitions of n-bitstrings.

__getitem__(label)[source]

Returns the affine subspace corresponding to the given label in this affine partition.

Parameters:

label (binvec | int)

Return type:

AffineSubspace

abstractmethod _get_subspace(label)[source]

Abstract method to be implemented by subclasses, providing the underlying logic for __getitem__.

Returns the affine subspace corresponding to the given label. The label vector has already been validated, and is guaranteed to have dimension equal to the label_dim for the partition.

Parameters:

label (binvec)

Return type:

AffineSubspace

_is_ortho(vec, label)[source]

Returns whether the given vector is orthogonal to the affine subspace corresponding to the given label in this affine partition, providing the underlying logic for AP.is_ortho.

The default implementation relies on producing the affine subspace and explicitly testing for orthogonality: subclasses can override this method to provide a more efficient implementation.

Parameters:
Return type:

bool

_label(vec)[source]

Returns the label of the given vector in this affine partition, providing the underlying logic for label.

The default implementation works by brute force search over all affine subspaces: subclasses can override this method to provide a more efficient implementation.

Parameters:

vec (binvec)

Return type:

binvec

property ambient_dim

The dimension of the ambient space.

Return type:

int

draw(axes, *, colors=None, label=None, subsp_kwargs=None, **draw_networkx_kwargs)[source]

Draws the affine partition using draw_networkx.

Parameters:
Return type:

None

property explicit

Returns an explicit representation of this affine partition.

Return type:

ExplicitAP

is_ortho(vec, label)[source]

Returns whether the given vector is orthogonal to the affine subspace corresponding to the given label in this affine partition

Parameters:
Return type:

bool

label(vec)[source]

Returns the label of the given vector in this affine partition.

Parameters:

vec (binvec)

Return type:

binvec

property label_dim

The dimension of the label vectors for subspaces in this partition

Return type:

int

property subsp_dim

The dimension of the affine subspaces in the partition.

Return type:

int

validate(*, num_vecs=None, num_labels=None, rng=None)[source]

Validates the partition:

  • checks that all subspaces have the correct dimensions

  • checks that all pairs of distinct subspaces are disjoint

  • checks that all vectors belong to the subspace with associated label

  • checks that orthogonality relationships are correct

If num_vecs and num_labels are not specified, the method will validate the partition using all possible vectors and labels, respectively. Otherwise, it will use the specified number of random vectors and labels.

Parameters:
Return type:

None