BaseModel#
- class pyqit.models.BaseModel[source]#
Bases:
_PyQitObjectBase class for all trainable models in PyQit.
Holds the weight registry: layers registered under a name, run with execute_qnode, and exposed as a flat dict keyed “<layer_name>.<weight_name>” on both backends. Classical layers register here with register_dense; BaseQuantumModel adds register_qnode.
- execute_qnode(name: str, X, **custom_weights)[source]#
Run the QNode or dense layer registered under name on a batch.
- Parameters:
name (str) – Name passed to register_qnode.
X (array-like)
**custom_weights – Flat “<name>.<weight>” overrides; unprefixed keys are ignored. Falls back to the model’s own weights when empty.
- Return type:
array-like
- register_dense(name: str, n_in: int, n_out: int, weights=None)[source]#
Register a classical dense layer
X @ weight.T + biasunder name.Lives in the same registry as the QNodes, so
weights,update_weights, checkpoints and the flat-kwargs routing cover it with no further plumbing. Run it withexecute_qnode.- Parameters:
name (str)
n_in (int)
n_out (int)
weights (dict, optional) –
{"weight", "bias"}from init_dense_weights; drawn when omitted.
- update_weights(flat_weights_dict)[source]#
Write flat_weights_dict into the model’s own weights.
No-op under torch, where autograd owns the nn.Parameter objects directly.
- Parameters:
flat_weights_dict (dict) – Keyed like weights.
- weight_groups() dict[source]#
weights keys by group,
"quantum"(QNodes) and"classical".Empty groups are omitted. The training loops build one optimizer per group, which is what lets
Trainer(learning_rate={...})set a rate per group.
- property weights#
Flat
{"<qnode_name>.<weight_name>": array}dict, both backends.