nkdsl.dsl.rewrite¶
Fluent immutable update-program builder for the symbolic operator DSL.
The Update class is designed for ergonomic construction of
site-update programs: every method is chainable and returns a new
immutable Update instance.
Module-level factory functions (shift, hop, write, swap, permute,
affine, scatter, identity) serve as zero-boilerplate entry points,
there is no need to first construct an empty Update() before chaining.
Examples:
from nkdsl.dsl import shift, hop, write, swap, permute, scatter
# Single operation, direct factory call
update = shift("i", +1)
# Compound update, chain freely
update = shift("i", -1).shift("j", +1) # hopping
update = hop("i", "j") # same hopping move
update = swap("i", "j").write("k", 0) # swap then zero
update = permute("i", "j", "k") # cyclic rotation
update = affine("i", scale=2, bias=-1) # x[i] = 2*x[i] - 1
# Bulk scatter to static flat indices
update = scatter([0, 5, 10], [val_0, val_5, val_10])
# Identity (no-op), for diagonal operators
update = identity()
# Conditional update
update = Update.cond(
site("i") > 0,
if_true=shift("i", -1),
if_false=write("i", 0),
)
Amplitude-side semantics¶
Amplitude expressions are evaluated after the emitted/connected state x'
has been constructed for the current branch.
By default:
- site("i").value refers to the source configuration x[i].
- emitted("i").value refers to the connected/emitted configuration x'[i].
This allows matrix elements to depend on either the source state, the emitted
state, or both. In addition, wrap_mod(expr) applies the same Hilbert-aware
modulo-wrap semantics used by shift_mod(...).
Connected-state dedup semantics¶
The padded connected-states representation returned by get_conn_padded is
deduplicated by default. If two terms (or two emissions within one term)
produce the same x', they are merged and their matrix elements are summed.
Zero-amplitude components are dropped before padding.
Set deduplicate_connected_components=False during .compile(...) to keep
raw per-branch output when needed.
Functions
|
Returns an |
|
Coerces user values into typed amplitude-expression nodes. |
|
Coerces user values into typed predicate-expression nodes. |
|
Returns an |
|
Returns the identity (no-op) |
|
Returns an |
|
Returns an |
|
Returns an |
|
Returns an Update performing a Hilbert-aware wrapped modular shift. |
|
Returns an |
|
Returns an |
Classes
|
Typed expression node for operator matrix elements. |
|
Special type indicating an unconstrained type. |
|
Symbolic selector for one Hilbert-space site iterator. |
|
Immutable, chainable site-update program builder. |
|
One primitive site-update operation. |
|
Ordered immutable sequence of site-update operations. |