ParameterPool¶
- class ParameterPool[source][source]¶
Bases:
objectProcess-global registry of OPNIC packet targets and the bound Quarc module.
Note
Single-thread constraint.
ParameterPoolstores all of its state on class-level attributes. It is designed for single-threaded use — one Quarc session per process at a time. There is no per-thread isolation; running multiple QUA programs concurrently from the same process is not supported. Per-thread isolation viathreading.localis a planned future enhancement.- classmethod iter_measurement_outcome_tables() Iterator[Any][source][source]¶
Yield live
MeasurementOutcomeTableinstances (debug/introspection).
- classmethod iter_measurement_register_fields() Iterator[Any][source][source]¶
Yield live
MeasurementRegisterFieldhandles (debug/introspection).
- classmethod lookup_runtime_parameter(name: str) 'Parameter' | None[source][source]¶
Return the runtime
Parameternamedname(excludes measurement fields).
- classmethod reset() None[source][source]¶
Clear all pool state — runtime registry, measurement registries, and Quarc module.
- classmethod guard_single_program_opnic(token: Any, *, table_name: str = '<unknown>') None[source][source]¶
Enforce that OPNIC structs are declared under a single QUA program scope.
The first OPNIC
declare()records its program-scopetoken; a laterdeclare()under a different token raises. Declaring multiple OPNIC tables in the same program is fine (same token). Callreset()to start a new program.
- classmethod iter_opnic_parameter_tables() List['ParameterTable'][source][source]¶
Return all registered OPNIC
ParameterTables, sorted by id.Includes synthetic single-field tables produced by standalone OPNIC parameter promotion.
- classmethod iter_standalone_opnic_parameters() List['Parameter'][source][source]¶
Return every OPNIC Parameter that is, or was, treated as standalone.
Union of parameters still in
_pending_standalone_opnicand parameters promoted into a synthetic single-fieldParameterTable(_is_synthetic_standalone == True). Pending entries come first, then promoted entries in registry order.
- classmethod has_quarc_module() bool[source][source]¶
Trueiff a Quarc module is currently bound to the pool.
- classmethod set_quarc_module(module: Any) None[source][source]¶
Bind an externally-built
BaseModule(or subclass) instance.Raises
RuntimeErrorif a module is already bound. Usereset()first if you genuinely need to swap.
- classmethod quarc_module() Any[source][source]¶
Return the bound Quarc module, lazily creating a default
QiskitQMModuleif none has been bound yet.After this method is called once with no pre-bound module,
_quarc_moduleis set to aQiskitQMModuleinstance (which sweeps pre-existing OPNIC pool state during__init__) and that becomes the slot; subsequent OPNICParameterTableconstructions emit eagerly into it.
- classmethod from_quarc_module(module: Any, opnic_runtime: Any | None = None) Dict[str, 'ParameterTable | Parameter'][source][source]¶
Wrap every struct in
moduleand return a parameter dict.This method operates in two modes depending on whether
moduleis a livequarc.BaseModuleinstance or a plaindict(e.g. loaded from arl_qoc_state.jsonfile).—
Mode 1 — Module object (quantum / generation side)
Input is a
quarc.BaseModule(or subclass) instance._struct_handlesare already populated (built byadd_struct()during construction). Each handle is paired with its struct spec to create aParameterTablewith_quarc_handle=handle.If
moduleis also aQiskitQMModule(hasparameter_specs), non-OPNIC objects are reconstructed viareconstruct_non_opnic()and merged into the result dict.The provided
modulebecomes the pool’s bound accumulator. Any previously- pending OPNICParameterTables are swept onto it.Mode 2 — Dictionary (classical entrypoint side)
Input is a
dict(the JSON loaded directly from the state file). Theopnic_runtimeargument must be provided."_structs"key → for each struct, the live endpoint is resolved onopnic_runtimevia_resolve_runtime_endpoint()(snake_case attribute first, then the raw_structskey)."parameter_specs"key (optional) → non-OPNIC objects reconstructed viafrom_spec()/from_spec().
—
1-field struct promotion rule (both modes): structs with exactly one field are returned as a standalone
Parameter; the wrapper table is flagged as_is_synthetic_standalone=Trueso all OPNIC transport delegates through it.- Parameters:
module – A
quarc.BaseModuleinstance or a state dict.opnic_runtime – Required when
moduleis a dict. Must expose each struct from"_structs"as a snake_case runtime attribute (with a fallback to the raw_structskey for already-snake struct names).
- Returns:
A
dictmapping snake-case struct name to the wrapper object (ParameterTablefor multi-field structs,Parameterfor 1-field structs), plus any non-OPNIC entries keyed byattr_name/ name.- Raises:
RuntimeError – If a module is already bound (Mode 1).
ValueError – If
moduleis a dict butopnic_runtimeis not provided, or if"_structs"key is absent.
- classmethod to_quarc_module(module: Any | None = None) Any[source][source]¶
Bind the pool slot to
module(or lazily create a defaultQiskitQMModule) and return it.Behaviour:
If
moduleis provided, behaves likeset_quarc_module()— binds the slot, raisingRuntimeErrorif a different module is already bound. Sweeping pre-existing pool state is only automatic whenmoduleis aQiskitQMModule(viaQiskitQMModule._sweep_preexisting_opnic()in__init__).If no module is bound yet, lazily creates a default
QiskitQMModule(same sweep semantics as an explicitQiskitQMModule()construction).Idempotent on subsequent calls — returns the same module reference.
Returns the bound module (typically
QiskitQMModule).