qlinks.variables package#
Submodules#
qlinks.variables.config module#
- class qlinks.variables.config.ConfigView(layout, array)[source]#
Bases:
objectLightweight read/write wrapper around a NumPy configuration array.
This is useful for readable operator code:
cfg.link(3) cfg.set_link(3, -cfg.link(3))
The underlying array is still a normal NumPy array.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- classmethod from_array(layout, array)[source]#
- Parameters:
layout (VariableLayout)
array (ArrayLike)
- Return type:
- classmethod default(layout)[source]#
- Parameters:
layout (VariableLayout)
- Return type:
- set_value(variable_index, value)[source]#
- Parameters:
variable_index (int)
value (int)
- Return type:
None
- flipped(variable_index)[source]#
Return a new config with a binary variable flipped.
This only works for variables with local values {0, 1}. For QLM flux variables {-1, +1}, use negated().
- Parameters:
variable_index (int)
- Return type:
- negated(variable_index)[source]#
Return a new config with one variable multiplied by -1.
This is useful for spin-1/2 QLM flux variables {-1, +1}.
- Parameters:
variable_index (int)
- Return type:
- __init__(layout, array)#
- Parameters:
layout (VariableLayout)
- Return type:
None
qlinks.variables.encoding module#
- class qlinks.variables.encoding.ConfigEncoder(layout)[source]#
Bases:
objectEncode configurations into hashable keys for basis lookup.
The default key is bytes from a canonical int64 representation. This is not always the most compressed representation, but it is robust for mixed site/link variables and arbitrary integer local values.
Later, for spin-1/2-only models, this can be supplemented by a bit-packed encoder.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- encode(config, *, validate=True)[source]#
- Parameters:
config (ArrayLike)
validate (bool)
- Return type:
bytes
- build_index(configs, *, validate=True)[source]#
- Parameters:
configs (Iterable[ArrayLike])
validate (bool)
- Return type:
dict[bytes, int]
- __init__(layout)#
- Parameters:
layout (VariableLayout)
- Return type:
None
- class qlinks.variables.encoding.BitPackedBinaryEncoder(layout)[source]#
Bases:
objectCompact encoder for pure binary layouts with local values {0, 1}.
This is useful for PXP, toric-code qubits, or dimer occupation variables.
It intentionally does not support {-1, +1} directly. For QLM flux variables, either use ConfigEncoder or convert values to binary codes first.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- encode(config, *, validate=True)[source]#
- Parameters:
config (ArrayLike)
validate (bool)
- Return type:
bytes
- __init__(layout)#
- Parameters:
layout (VariableLayout)
- Return type:
None
qlinks.variables.layout module#
- class qlinks.variables.layout.VariableKind(*values)[source]#
Bases:
StrEnum- SITE = 'site'#
- LINK = 'link'#
- class qlinks.variables.layout.HasSiteLinkCounts(*args, **kwargs)[source]#
Bases:
ProtocolMinimal protocol expected from the future lattice layer.
A concrete lattice does not need to inherit from this protocol. It only needs to expose num_sites and/or num_links.
- num_sites: int#
- num_links: int#
- __init__(*args, **kwargs)#
- class qlinks.variables.layout.VariableSpec(kind, geometry_index, local_space)[source]#
Bases:
objectOne variable in the flattened configuration array.
- kind:
Whether this variable lives on a site or link.
- geometry_index:
Site index or link index in the lattice layer.
- local_space:
Allowed values for this variable.
- Parameters:
kind (VariableKind)
geometry_index (int)
local_space (LocalSpace)
- kind: VariableKind#
- geometry_index: int#
- local_space: LocalSpace#
- __init__(kind, geometry_index, local_space)#
- Parameters:
kind (VariableKind)
geometry_index (int)
local_space (LocalSpace)
- Return type:
None
- class qlinks.variables.layout.VariableLayout(specs)[source]#
Bases:
objectMap physical site/link variables to positions in a compact NumPy config array.
The computational basis state is represented as
config[var_index]
This class tells us which var_index corresponds to which site/link variable.
- Parameters:
specs (tuple[VariableSpec, ...])
- specs: tuple[VariableSpec, ...]#
- classmethod from_sites(num_sites, local_space)[source]#
- Parameters:
num_sites (int)
local_space (LocalSpace)
- Return type:
- classmethod from_links(num_links, local_space)[source]#
- Parameters:
num_links (int)
local_space (LocalSpace)
- Return type:
- classmethod from_sites_and_links(num_sites, site_space, num_links, link_space)[source]#
- Parameters:
num_sites (int)
site_space (LocalSpace)
num_links (int)
link_space (LocalSpace)
- Return type:
- classmethod from_lattice_sites(lattice, local_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
local_space (LocalSpace)
- Return type:
- classmethod from_lattice_links(lattice, local_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
local_space (LocalSpace)
- Return type:
- classmethod from_lattice_sites_and_links(lattice, site_space, link_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
site_space (LocalSpace)
link_space (LocalSpace)
- Return type:
- property n_variables: int#
- property shape: tuple[int]#
- variable_index(kind, geometry_index)[source]#
- Parameters:
kind (VariableKind | str)
geometry_index (int)
- Return type:
int
- default_config()[source]#
Return a valid default configuration.
For each variable, choose the first value in its local space.
- as_metadata()[source]#
Small serializable summary useful for debugging or future IO.
- Return type:
dict[str, Any]
- __init__(specs)#
- Parameters:
specs (tuple[VariableSpec, ...])
- Return type:
None
qlinks.variables.local_space module#
- class qlinks.variables.local_space.LocalSpace(values)[source]#
Bases:
objectFinite local Hilbert/configuration space for one physical variable.
Examples
- Spin-1/2 site:
values = [0, 1]
- QLM spin-1/2 electric field:
values = [-1, 1]
- Dimer occupation:
values = [0, 1]
- classmethod spin_half_flux()[source]#
Spin-1/2 QLM-like electric flux variable.
This uses integer values {-1, +1}; if you prefer physical values {-1/2, +1/2}, keep this integer representation internally and divide by 2 only when evaluating physical observables.
- Return type:
- property dim: int#
- value_to_code(value)[source]#
Convert a physical local value to a dense integer code 0, …, dim - 1.
- Parameters:
value (int)
- Return type:
int
Module contents#
- class qlinks.variables.BitPackedBinaryEncoder(layout)[source]#
Bases:
objectCompact encoder for pure binary layouts with local values {0, 1}.
This is useful for PXP, toric-code qubits, or dimer occupation variables.
It intentionally does not support {-1, +1} directly. For QLM flux variables, either use ConfigEncoder or convert values to binary codes first.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- encode(config, *, validate=True)[source]#
- Parameters:
config (ArrayLike)
validate (bool)
- Return type:
bytes
- __init__(layout)#
- Parameters:
layout (VariableLayout)
- Return type:
None
- class qlinks.variables.ConfigEncoder(layout)[source]#
Bases:
objectEncode configurations into hashable keys for basis lookup.
The default key is bytes from a canonical int64 representation. This is not always the most compressed representation, but it is robust for mixed site/link variables and arbitrary integer local values.
Later, for spin-1/2-only models, this can be supplemented by a bit-packed encoder.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- encode(config, *, validate=True)[source]#
- Parameters:
config (ArrayLike)
validate (bool)
- Return type:
bytes
- build_index(configs, *, validate=True)[source]#
- Parameters:
configs (Iterable[ArrayLike])
validate (bool)
- Return type:
dict[bytes, int]
- __init__(layout)#
- Parameters:
layout (VariableLayout)
- Return type:
None
- class qlinks.variables.ConfigView(layout, array)[source]#
Bases:
objectLightweight read/write wrapper around a NumPy configuration array.
This is useful for readable operator code:
cfg.link(3) cfg.set_link(3, -cfg.link(3))
The underlying array is still a normal NumPy array.
- Parameters:
layout (VariableLayout)
- layout: VariableLayout#
- classmethod from_array(layout, array)[source]#
- Parameters:
layout (VariableLayout)
array (ArrayLike)
- Return type:
- classmethod default(layout)[source]#
- Parameters:
layout (VariableLayout)
- Return type:
- set_value(variable_index, value)[source]#
- Parameters:
variable_index (int)
value (int)
- Return type:
None
- flipped(variable_index)[source]#
Return a new config with a binary variable flipped.
This only works for variables with local values {0, 1}. For QLM flux variables {-1, +1}, use negated().
- Parameters:
variable_index (int)
- Return type:
- negated(variable_index)[source]#
Return a new config with one variable multiplied by -1.
This is useful for spin-1/2 QLM flux variables {-1, +1}.
- Parameters:
variable_index (int)
- Return type:
- __init__(layout, array)#
- Parameters:
layout (VariableLayout)
- Return type:
None
- class qlinks.variables.LocalSpace(values)[source]#
Bases:
objectFinite local Hilbert/configuration space for one physical variable.
Examples
- Spin-1/2 site:
values = [0, 1]
- QLM spin-1/2 electric field:
values = [-1, 1]
- Dimer occupation:
values = [0, 1]
- classmethod spin_half_flux()[source]#
Spin-1/2 QLM-like electric flux variable.
This uses integer values {-1, +1}; if you prefer physical values {-1/2, +1/2}, keep this integer representation internally and divide by 2 only when evaluating physical observables.
- Return type:
- property dim: int#
- value_to_code(value)[source]#
Convert a physical local value to a dense integer code 0, …, dim - 1.
- Parameters:
value (int)
- Return type:
int
- class qlinks.variables.VariableLayout(specs)[source]#
Bases:
objectMap physical site/link variables to positions in a compact NumPy config array.
The computational basis state is represented as
config[var_index]
This class tells us which var_index corresponds to which site/link variable.
- Parameters:
specs (tuple[VariableSpec, ...])
- specs: tuple[VariableSpec, ...]#
- classmethod from_sites(num_sites, local_space)[source]#
- Parameters:
num_sites (int)
local_space (LocalSpace)
- Return type:
- classmethod from_links(num_links, local_space)[source]#
- Parameters:
num_links (int)
local_space (LocalSpace)
- Return type:
- classmethod from_sites_and_links(num_sites, site_space, num_links, link_space)[source]#
- Parameters:
num_sites (int)
site_space (LocalSpace)
num_links (int)
link_space (LocalSpace)
- Return type:
- classmethod from_lattice_sites(lattice, local_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
local_space (LocalSpace)
- Return type:
- classmethod from_lattice_links(lattice, local_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
local_space (LocalSpace)
- Return type:
- classmethod from_lattice_sites_and_links(lattice, site_space, link_space)[source]#
- Parameters:
lattice (HasSiteLinkCounts)
site_space (LocalSpace)
link_space (LocalSpace)
- Return type:
- property n_variables: int#
- property shape: tuple[int]#
- variable_index(kind, geometry_index)[source]#
- Parameters:
kind (VariableKind | str)
geometry_index (int)
- Return type:
int
- default_config()[source]#
Return a valid default configuration.
For each variable, choose the first value in its local space.
- as_metadata()[source]#
Small serializable summary useful for debugging or future IO.
- Return type:
dict[str, Any]
- __init__(specs)#
- Parameters:
specs (tuple[VariableSpec, ...])
- Return type:
None
- class qlinks.variables.VariableSpec(kind, geometry_index, local_space)[source]#
Bases:
objectOne variable in the flattened configuration array.
- kind:
Whether this variable lives on a site or link.
- geometry_index:
Site index or link index in the lattice layer.
- local_space:
Allowed values for this variable.
- Parameters:
kind (VariableKind)
geometry_index (int)
local_space (LocalSpace)
- kind: VariableKind#
- geometry_index: int#
- local_space: LocalSpace#
- __init__(kind, geometry_index, local_space)#
- Parameters:
kind (VariableKind)
geometry_index (int)
local_space (LocalSpace)
- Return type:
None