quchip.engine.stage2_assembly¶
Stage 2: assemble a HamiltonianDescription from chip, drive ops, and frame.
Responsibilities¶
This module owns the 2π boundary of the engine: inputs are ordinary
GHz (ν), outputs are operators scaled by
ω = 2π·ν so backends can solve Schrödinger’s equation with d|ψ⟩/dt =
-i H |ψ⟩ in ns/rad units. The operator angular-scaling boundary lives
entirely here, in:
_build_static_h0()— frame-subtracted bare Hamiltonian,_collect_coupling_terms()— full interaction band-decomposed, each band filtered by the coupling’s RWA policy and folded intoH₀or carried, per band,_apply_2pi_canonical()— the single point that scales every embedded dynamic operator (drive, crosstalk, coupling-dynamic, device-dynamic).
The same 2π convention also expresses signal-AST carrier and
rotating-frame-phase frequencies in rad/ns
(_single_tone_coefficient(), _direct_real_coefficient()) and
the stage-3 demodulation phase; those are frequencies inside the
time-dependence / observable bookkeeping, not a second Hamiltonian
boundary. quchip.engine.solver_hints divides by 2π only to
report advisory hints back in ordinary GHz.
Physics¶
Stage 2 performs three physically distinct operations on top of the 2π scaling:
Rotating-frame transformation. Each device’s number operator is shifted by its frame reference ω_ref so that the static Hamiltonian becomes
H₀ − Σᵢ ω_ref,ᵢ nᵢ(see any standard cQED reference, e.g. Scully & Zubairy, Quantum Optics, CUP 1997, §5.1).Band decomposition / rotating-wave approximation (RWA). Coupling and drive operators are split into excitation-change bands of weight
w = col − rowand attached to carriersexp(−i w·ω t). Whenrwa=True, counter-rotating coupling bands are dropped structurally by the coupling’srwa_keeps_bandpredicate and counter-rotating drive bands by the modulation policies (Jaynes & Cummings, Proc. IEEE 51, 89 (1963); Walls & Milburn, Quantum Optics, Springer 2008, §10.3; for dispersive/structured cases see Gambetta et al., PRA 74, 042318 (2006), and the cross-resonance treatment in Magesan & Gambetta, PRA 101, 052308 (2020)).Signal-program construction. Time dependence is emitted as a
SignalProgramAST — a pure, JAX-traceable description that backends lower into their native coefficient form.
Functions
|
One-shot stage 2: compile the template then instantiate a single variant. |
|
Compile the invariant Hamiltonian skeleton (H₀, couplings, pre-embedded drive bands). |
Rebuild signal-program leaves from drive_ops and attach them to the template's operators. |
Classes
|
Per-Fourier-band context for the stage-2 modulation dispatch. |
|
One pre-embedded, 2π-scaled drive band plus its reinstantiation metadata. |
- class quchip.engine.stage2_assembly.BandContext(weight, device_frame_freq, drive_freq, rwa)[source]¶
Bases:
objectPer-Fourier-band context for the stage-2 modulation dispatch.
- Parameters:
weight (int) – Fourier band index (e.g.
-1,0,+1for a single-mode device; arbitrary integer for higher bands).device_frame_freq (float) – Device-frame oscillation frequency for this band, GHz.
drive_freq (float | None) – Carrier frequency for microwave drives, GHz;
Nonefor baseband (flux-like) drives.rwa (bool) – Whether the engine is assembling in the rotating-wave approximation.
- class quchip.engine.stage2_assembly.CompiledDriveTerm(operator, drive_index, modulation, weight, device_frame_freq, rwa, origin='drive', tag=None)[source]¶
Bases:
objectOne pre-embedded, 2π-scaled drive band plus its reinstantiation metadata.
Template-internal (stored on
drive_terms, never handed to backends). During sweep instantiation, stage 2 combinesweight,device_frame_freq, the variant’s drive frequency, andrwainto aBandContext, then dispatches on the channel’sDriveModulationtag to emit the variant-specificScalarModulationforoperator.device_frame_freqis in GHz (may be a traced scalar; seeResolvedFrame).- Parameters:
operator (CanonicalOperator)
drive_index (int)
modulation (DriveModulation)
weight (int)
device_frame_freq (Any)
rwa (bool)
origin (Literal['device', 'coupling', 'drive', 'crosstalk', 'flux'])
tag (str | None)
- operator: CanonicalOperator¶
- modulation: DriveModulation¶
- quchip.engine.stage2_assembly.compile_hamiltonian_template(chip, drive_ops, *, resolved_frame)[source]¶
Compile the invariant Hamiltonian skeleton (H₀, couplings, pre-embedded drive bands).
Everything that does not change across a homogeneous sweep lives in the template: static Hamiltonian, static-coupling folds, invariant dynamic couplings, and band-decomposed drive operators pre-embedded and pre-scaled by 2π. Per-sweep instantiation (
instantiate_hamiltonian_description()) rebuilds only theSignalProgramleaves, so envelope parameters, drive frequencies, phases, and frame scalars can sweep through JAX without retracing operator tensors.- Parameters:
chip (Chip)
drive_ops (list['DriveOp'])
resolved_frame (ResolvedFrame)
- Return type:
- quchip.engine.stage2_assembly.instantiate_hamiltonian_description(template, drive_ops, chip)[source]¶
Rebuild signal-program leaves from drive_ops and attach them to the template’s operators.
- Parameters:
template (HamiltonianTemplate)
drive_ops (list['DriveOp'])
chip (Chip)
- Return type:
- quchip.engine.stage2_assembly.build_hamiltonian_description(chip, drive_ops, *, resolved_frame)[source]¶
One-shot stage 2: compile the template then instantiate a single variant.
Equivalent to
compile_hamiltonian_template()followed byinstantiate_hamiltonian_description()with the samedrive_ops. Prefer the two-step form when solving many variants that share the same chip topology.- Parameters:
chip (Chip) – The chip whose device, coupling, and drive Hamiltonians are assembled (2π applied at this boundary).
drive_ops (list of DriveOp) – Scheduled drive operations to embed as dynamic terms.
resolved_frame (ResolvedFrame) – Stage-1 frame result carrying the per-device frame frequencies, demodulation frequencies, and frame mode.
- Returns:
Static terms, dynamic terms, and dropped-term records for the single variant.
- Return type: