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.
- layout: VariableLayout#
- 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().
- 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}.
- __init__(layout, array)#
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.
- layout: VariableLayout#
- __init__(layout)#
- 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.
- layout: VariableLayout#
- __init__(layout)#
qlinks.variables.layout module#
- class qlinks.variables.layout.VariableKind(*values)[source]#
Bases:
StrEnumKind of physical variable represented in a layout.
- 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.
- __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.
- kind: VariableKind#
- local_space: LocalSpace#
- __init__(kind, geometry_index, local_space)#
- 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.
- specs: tuple[VariableSpec, ...]#
- default_config()[source]#
Return a valid default configuration.
For each variable, choose the first value in its local space.
- __init__(specs)#
qlinks.variables.local_space module#
- class qlinks.variables.local_space.LocalSpace(values)[source]#
Bases:
objectFinite local Hilbert/configuration space for one variable.
- values#
Allowed integer values for the variable.
- Type:
numpy.ndarray[tuple[Any, …], numpy.dtype[numpy.integer]]
Examples
Spin-1/2 site or dimer occupation uses
[0, 1]. A spin-half QLM electric field uses[-1, 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.
- __init__(values)#
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.
- layout: VariableLayout#
- __init__(layout)#
- 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.
- layout: VariableLayout#
- __init__(layout)#
- 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.
- layout: VariableLayout#
- 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().
- 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}.
- __init__(layout, array)#
- class qlinks.variables.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.
- __init__(*args, **kwargs)#
- class qlinks.variables.LocalSpace(values)[source]#
Bases:
objectFinite local Hilbert/configuration space for one variable.
- values#
Allowed integer values for the variable.
- Type:
numpy.ndarray[tuple[Any, …], numpy.dtype[numpy.integer]]
Examples
Spin-1/2 site or dimer occupation uses
[0, 1]. A spin-half QLM electric field uses[-1, 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.
- __init__(values)#
- class qlinks.variables.VariableKind(*values)[source]#
Bases:
StrEnumKind of physical variable represented in a layout.
- SITE = 'site'#
- LINK = 'link'#
- 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.
- specs: tuple[VariableSpec, ...]#
- default_config()[source]#
Return a valid default configuration.
For each variable, choose the first value in its local space.
- __init__(specs)#
- 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.
- kind: VariableKind#
- local_space: LocalSpace#
- __init__(kind, geometry_index, local_space)#