q1ss.ap.generated
Generated affine partitions.
APMatrixGen
- class APMatrixGen(ambient_dim, max_label_dim=None)[source]
Bases:
ABCAbstract base class for generators of invertible matrices, used to construct instances of
GenAP.- __call__(label)[source]
Given a
k-dimensional label vector, returns the pair of a(n-k)-dimensional matrix and its inverse, wherenis the ambient dimension for the generator.
- abstractmethod _get_matrix(label)[source]
Abstract method to be implemented by subclasses.
Given a
k-dimensional label vector, returns the pair of an-k-dimensional matrix and its inverse, wherenis theambient_dimfor the generator.The label vector has already been validated, and is guaranteed to have dimension between 0 and
max_label_dim, both inclusive.
- property ambient_dim
The dimension of the ambient space for the generated matrices.
- Return type:
- static eye(ambient_dim)[source]
Generator of identity matrices.
- Parameters:
ambient_dim (
int)- Return type:
- property max_label_dim
The maximum dimension of labels for which matrices can be generated. Maximum is
ambient_dimminus 1.- Return type:
EyeAPMatrixGen
- class EyeAPMatrixGen(ambient_dim)[source]
Bases:
APMatrixGenGenerator of identity matrices.
GenAP
- final class GenAP(subsp_dim, generator)[source]
Bases:
APClass for ordered balanced affine partitions of
n-bitstrings defined by a generator of invertible matrices for partial labels.- static __new__(cls, subsp_dim, generator)[source]
Constructs a new affine partition from the given labelled matrix generator.
- Parameters:
subsp_dim (
int)generator (
APMatrixGen)
- Return type:
- _get_subspace(label)[source]
Returns the affine subspace corresponding to the given label, providing the underlying logic for
__getitem__.Let
kbe thelabel_dimandnbe theambient_dimfor this generator, so thatn-kis thesubsp_dim.Start from the standard affine subspace spanned by the first
n-kstandard basis vectors. The basepoint is given by a vector which is zero on the firstn-kcomponents, and is the reverse of the label on the remainingkcomponents.Generate a sequence of
k-1(matrix, inverse) pairs using partial labels, starting fromlabel[:-1]and ending with the empty binary vectorbinvec([]).Transform the standard subspace using the inverse matrices in the sequence, where matrix at index
iacts on the subspace spanned by the firstn-k+1+istd. basis vectors (n-k+1->n).
Uses the
AffineSubspace.transformmethod withpartial=True.- Parameters:
label (
binvec)- Return type:
- _label(vec)[source]
Returns the label of the given vector in this affine partition, providing the underlying logic for
label.Let
kbe thelabel_dimandnbe theambient_dimfor this generator.Start from the given vector.
For each
i in range(k), generates a matrix using the lastibits of the vector, read in reverse, then applies the matrix to the firstn-ibits of the vector.Returns the last
kbits of the resulting vector, read in reverse.
Note that each matrix application keeps fixed the bits of the vector upon which the matrix itself depended.
- property generator
The labelled matrix generator for this affine partition.
- Return type:
RandomAPMatrixGen
- class RandomAPMatrixGen(ambient_dim, seed)[source]
Bases:
APMatrixGenGenerator of random invertible matrices.
Warning
Currently, this is based on NumPy’s pseudo-random generator: it is not possible to generate oracles for affine partitions based on this class of generators.
In the future, an optional circuit property will be included in the
APMatrixGenclass, allowing for the automatic generation of oracles forGenAPinstances. The functionality of this class will be extended to support circuit-defined pseudorandom functions, and NumPy’s random number generator will be deprecated.- static __new__(cls, ambient_dim, seed)[source]
Constructs a generator of random invertible matrices with given ambient dimension and seed.
- _get_matrix(label)[source]
On a
k-dimensional label, returns the pair of a random(n-k)-dimensional invertible matrix and its invers, wherenis theambient_dim.The matrix and its inverse are sampled using
binmat.random_inv, using a random number generator seeded by a combination of the label, the ambient dimension, and theseedprovided.