Runtime¶
The execution-facing layer: the contract every backend adapter implements, the configuration model, and the command-line entry point.
Executor¶
Base abstraction for quantum circuit executors.
This module defines the contract that all quantum backend adapters must implement, including circuit creation, application construction, and application execution.
It belongs to the runtime layer, so imports from backend-specific
packages such as netqasm or cunqa must not appear here.
- class netqmpi.runtime.executor.Executor[source]¶
Bases:
ABCAbstract base class for quantum backend executors.
This interface combines three responsibilities into a single adapter contract:
Circuit factory through
create_circuit().Application builder through
build_apps().Application runner through
run().
- Variables:
size – Number of nodes or resources managed by the executor.
config – Backend-specific configuration dictionary.
- property size: int¶
Return the number of nodes or resources managed by this executor.
- Returns:
The executor size.
- property config: Dict[str, Any]¶
Return the backend-specific configuration.
- Returns:
The configuration dictionary.
- abstractmethod create_circuit(num_qubits, num_clbits, comm)[source]¶
Create a backend-specific quantum circuit.
- Parameters:
num_qubits (int) – Number of qubits in the circuit.
num_clbits (int) – Number of classical bits in the circuit.
comm (QMPICommunicator) – Communicator associated with the circuit.
- Returns:
A backend-specific
Circuit.- Return type:
- abstractmethod build_apps(file, size)[source]¶
Load a script and build the rank-specific application instances.
Each rank receives an injected
Environmentexposing this executor’screate_circuit()factory.
- abstractmethod run(apps)[source]¶
Execute an application instance with the given configuration.
- Parameters:
app_instance – Object returned by
build_apps().config – Simulation or execution parameters. Backend adapters may accept a subclass of
RunConfigwith additional backend-specific fields.apps (Any)
- Return type:
None
Run configuration¶
Backend-agnostic configuration for running a NetQMPI application.
This module defines a runtime configuration object that uses only primitive Python types, ensuring that the runtime layer remains fully decoupled from any specific backend (e.g. NetQASM, CUNQA, Qoala).
Backend adapters may subclass RunConfig to introduce additional
fields required by their simulator or hardware. All configuration is
loaded from a single YAML file (see read_config_block()) instead of
per-backend command-line flags, so the CLI stays small as backends grow.
- class netqmpi.runtime.run_config.RunConfig[source]¶
Bases:
objectConfiguration for a single NetQMPI simulation run.
All fields rely on plain Python types. Backend-specific parameters (such as NetQASM formalism or Qoala qdevice noise) should be provided by subclasses defined in the corresponding adapter packages.
- Variables:
shots (int) – Number of times the simulation is repeated.
- classmethod from_dict(data)[source]¶
Build a config from a plain dict, mapping keys to dataclass fields.
Unknown keys raise
ValueErrorso typos in a YAML config surface immediately instead of being silently ignored. Subclasses with nested/structured fields (e.g. a qdevice block) should override this to translate those keys before delegating here.
- netqmpi.runtime.run_config.read_config_block(path, backend)[source]¶
Read a NetQMPI YAML config file and return the settings for one backend.
The file mixes generic (shared) settings at the top level with optional per-backend blocks keyed by backend name. Only the block for
backendis merged on top of the generic settings; blocks for other backends are ignored. Example:shots: 1000 seed: 7 qoala: link_fidelity: 0.8 hardware: t1: 0
Reading this with
backend="qoala"yields{"shots": 1000, "seed": 7, "link_fidelity": 0.8, "hardware": {...}}.
Command-line interface¶
NetQMPI command-line entry point.
This module is intentionally free of backend-specific imports from the
core runtime logic. All simulator-specific behavior is delegated to an
Executor implementation provided by
the corresponding adapter package.
- netqmpi.runtime.cli.simulate(script, num_procs=1, executor=None, config=None, timer=False)[source]¶
Build and run a NetQMPI script using the given backend executor.
- Parameters:
script (str) – Path to the NetQMPI Python script.
num_procs (int) – Number of parallel quantum nodes.
executor (Executor | None) – Backend executor to use. If
None, aNetQASMExecutorAdapteris used by default.config (RunConfig | None) – Simulation parameters. If
None, a defaultRunConfiginstance is used.timer (bool) – If
True, print the wall-clock execution time.
- Return type:
None
- netqmpi.runtime.cli.write_metrics(path, metrics)[source]¶
Write the metrics of a run to a JSON file, for
--metrics.Only the metrics are written, not the configuration of the run. A backend that reports none gets an empty object and a note on stderr, so that a sweep over backends always finds a file to read.
- netqmpi.runtime.cli.main()[source]¶
Parse command-line arguments and execute the requested NetQMPI script.
The selected backend adapter is instantiated from the provided flags and passed to
simulate().
Simulation plugins¶
Simulation plugins: what NetQMPI expects of one, and how it finds it.
A plugin customises how a backend simulates the network: a hardware model, a
link model, readout error. NetQMPI does not interpret it. It finds the
plugin, hands it plugin_config unread, and keeps the context manager the
plugin returns open for the length of the simulation. Which backends accept
plugins is up to each backend’s run config, which has a plugin key when
it does (today only the NetQASM backend’s).
A plugin is named in one of two ways:
By a short name, without a colon, which is looked up in the
netqmpi.pluginsentry-point group. This is how an installed plugin package is used:# pyproject.toml of the plugin package [project.entry-points."netqmpi.plugins"] nv_2026 = "netqmpi_colorcenters:nv_2026"
As
"module:callable", with the module imported the waypython -mwould import it: the working directory first.
Nothing here imports a backend, so netqmpi --list-plugins works whatever
simulator is installed.
- netqmpi.plugins.GROUP = 'netqmpi.plugins'¶
The entry-point group plugin packages register their plugins in.
- class netqmpi.plugins.Plugin[source]¶
Bases:
ProtocolWhat NetQMPI requires of a plugin, as a
typing.Protocol.Only
__call__is required, so a plain function is a plugin. NetQMPI reads three further members withgetattr, each optional:run_defaultsA mapping of run-config keys to the values the plugin needs, for example
{"formalism": "dm", "num_qubits": 3}. They take the place of the backend’s own defaults; anything the config file or the command line sets still wins. They are applied when the config is built from a file or the command line, through the run config’sfrom_dict.configure(plugin_config, run_config)Called once when the run config is built, before any rank is traced, with copies of
plugin_configand of the final run config. It validates them and raisesValueErroron a bad value or an incompatible setting; whatever it changes is discarded.backendsThe backends the plugin is written for, e.g.
("netqasm",). A backend not in it refuses the plugin. Without it, any backend that accepts plugins does.
- __init__(*args, **kwargs)¶
- class netqmpi.plugins.InstalledPlugin[source]¶
Bases:
objectA plugin registered in the
netqmpi.pluginsentry-point group.- Variables:
- netqmpi.plugins.installed()[source]¶
List the plugins installed through entry points, sorted by name.
Reads each installed distribution’s entry points rather than calling
importlib.metadata.entry_points, whose signature changed in Python 3.10; this works the same from 3.8 on and also gives the distribution that provides each plugin. A distribution found twice onsys.pathcounts once, as the first copy, which is the one Python imports.- Returns:
One entry per plugin and distribution.
- Return type:
- netqmpi.plugins.load(spec)[source]¶
Find the plugin a run config names.
- Parameters:
spec (str) – A short name registered in the
netqmpi.pluginsentry-point group, or"package.module:callable".- Returns:
The plugin – a callable that takes
plugin_config.- Raises:
ValueError – If no installed plugin has the short name, two distributions provide it,
specis a malformedmodule:callable, or what it names cannot be imported or is not callable.- Return type:
- netqmpi.plugins.run_defaults(plugin, spec, config_cls)[source]¶
Read and check the run-config defaults a plugin asks for.
- Parameters:
- Returns:
A copy of
plugin.run_defaults, or{}if it has none.- Raises:
ValueError – If
run_defaultsis not a mapping, names a key the run config does not have, or setsplugin/plugin_config. The message names the plugin: the user’s config is not at fault.- Return type:
- netqmpi.plugins.check_backend(plugin, spec, backend)[source]¶
Refuse a plugin whose
backendsdoes not includebackend.- Parameters:
- Raises:
ValueError – If the plugin declares backends and
backendis not one of them.- Return type:
None
- netqmpi.plugins.configure(plugin, run_config)[source]¶
Let a plugin check the run config it will run under.
The plugin’s
configure, if it has one, is called with a deep copy ofplugin_configand a copy ofrun_configthat carries another, so it can read both but change neither. The run config itself is copied shallowly: it may hold objects, such aspost_function, that cannot be deep-copied.- Parameters:
- Raises:
Exception – Whatever the plugin’s
configureraises;ValueErroris the documented choice.- Return type:
None