quchip.interop.base¶
Library-agnostic registry and dispatch for third-party model mappings.
A ModelMapping subclass authors a one-directional or bidirectional
conversion between a third-party circuit-QED object and a quchip device.
Subclasses register at class-definition time, keyed by the third-party type
they import from, the (library, quchip type) pair they export to, or both.
Concrete mappings (e.g. for scqubits) live in sibling modules that import both
sides.
Functions
|
Export quchip device to a third-party object of library. |
|
Import third-party obj into a quchip device through a registered mapping. |
Return a copy of the import registry, keyed by source key. |
|
|
Return the registry key for third-party type tp. |
Classes
Base class for a single third-party <-> quchip device conversion. |
- quchip.interop.base.source_key(tp)[source]¶
Return the registry key for third-party type tp.
The key is the type’s top-level module name joined with its qualified name, e.g.
"scqubits.Transmon". Only the top-level module is used, so a mapping registered against a package root matches classes re-exported from submodules.
- class quchip.interop.base.ModelMapping[source]¶
Bases:
objectBase class for a single third-party <-> quchip device conversion.
- Variables:
source (str or None) – Registry key (see
source_key()) of the third-party type this mapping imports from.Nonemeans the mapping supports export only.target (type or None) – quchip device type this mapping exports to. Required when
export_model()is overridden.Nonemeans import-only.library (str or None) – Name of the third-party library this mapping exports for. Defaults to
source.split(".")[0]whensourceis set. Export-only mappings must set it explicitly.automatically (Subclassing registers the mapping)
- :ivar * setting
sourceregisters it forimport_object()under that: key. A second subclass that reuses the samesourceraises TypeErrorat class-definition time.- :ivar * overriding
export_model()registers it forexport_object(): under(library, target). An override withouttarget, or without a resolvable
library(nosourceto default it from), raisesTypeError. A second subclass that reuses the same(library, target)pair raisesTypeErrornaming both classes.
- Variables:
export_model (The abstract base itself (source is None and no)
nothing. (override) registers)
- import_model(obj, **opts)[source]¶
Convert third-party object obj into a quchip device.
Override to support import. The base implementation raises
NotImplementedError.
- export_model(device, **opts)[source]¶
Convert quchip device into a third-party object.
Override to support export, and also set
target. The base implementation raisesNotImplementedError.
- quchip.interop.base.import_object(obj, **opts)[source]¶
Import third-party obj into a quchip device through a registered mapping.
Walks
type(obj).__mro__and dispatches to the firstModelMappingregistered under that class’ssource_key().- Raises:
LookupError – No mapping is registered for
type(obj)or any of its base classes. The message names the missing source key and shows a skeleton for authoring a newModelMapping.- Parameters:
- Returns:
Converted quchip model.
- Return type:
- quchip.interop.base.export_object(device, library, **opts)[source]¶
Export quchip device to a third-party object of library.
Walks
type(device).__mro__and dispatches to the firstModelMappingregistered under(library, that class).- Raises:
LookupError – No mapping is registered for
(library, type(device))or any base class. The message lists the device types library can export.- Parameters:
device (BaseDevice) – Device whose type selects the registered mapping.
library (str) – Registered target library, such as
"scqubits".**opts (Any) – Keywords forwarded unchanged to the mapping’s conversion method, which documents supported keys and defaults.
- Returns:
Converted third-party object.
- Return type: