quchip.declarative.expr¶
Backend-neutral operator algebra for the declarative physics DSL.
PhysicsExpr is the expression tree LocalOps
handles compose into; compile_expr() lowers a tree into a backend-native
operator once endpoint labels are resolved to concrete Hilbert spaces.
Functions
|
Compile a |
|
Coerce a scalar-like value into |
Classes
|
A time-dependent scalar payload attached to a |
|
Backend-neutral expression tree for local physics operators. |
- class quchip.declarative.expr.DynamicScalar(source)[source]¶
Bases:
objectA time-dependent scalar payload attached to a
PhysicsExpr.sourceis the time-dependent object (typically an envelope or aScalarModulation) that the engine compiles into aDynamicTermwhen assembling the Hamiltonian. Multiplying aDynamicScalarby aPhysicsExprrecords the source on the resulting expression’sdynamic_sourcestuple — the operator structure itself is unchanged.- Parameters:
source (Any)
- class quchip.declarative.expr.PhysicsExpr(kind, args=(), labels=(), scalar=1.0, dynamic_sources=())[source]¶
Bases:
objectBackend-neutral expression tree for local physics operators.
Built by composing
LocalOpsoperator handles, not constructed directly. Operators on the same endpoint compose with@(matrix product); operators on different endpoints combine with*(tensor product). Scalars scale via*, and an envelope or modulation multiplied in is recorded as a dynamic source rather than altering the operator structure.Examples
>>> from quchip.declarative import LocalOps >>> a, b = LocalOps("q0", 3), LocalOps("q1", 3) >>> coupling = 0.01 * (a.a * b.adag + a.adag * b.a) >>> coupling.kind 'add' >>> coupling.labels ('q0', 'q1')
- Parameters:
- dynamic_sources: tuple[DynamicScalar, ...] = ()¶
- quchip.declarative.expr.ensure_expr(value)[source]¶
Coerce a scalar-like value into
PhysicsExpr.- Parameters:
value (Any)
- Return type:
- quchip.declarative.expr.compile_expr(expr, op_lookup, backend)[source]¶
Compile a
PhysicsExprinto a backend-native operator.op_lookupmaps(label, operator_name)to a backend operator (e.g.a,adag,n,Ifor each device label).backendis the active default backend; only itstensor()method is used here. Scalar coefficients carried by every node are preserved consistently — including traced (non-concrete) scalars, which are multiplied unconditionally so gradients still flow.