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 themselves at class-definition time, keyed by the
third-party type they import from and/or the (library, quchip type) pair
they export to. Nothing in this module depends on any specific third-party
library; 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 via 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 that 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.
- source¶
Registry key (see
source_key()) of the third-party type this mapping imports from.Nonemeans the mapping supports export only.- Type:
str or None
- target¶
The quchip device type this mapping exports to. Required whenever
export_model()is overridden;Nonemeans import-only.- Type:
type or None
- library¶
Name of the third-party library this mapping exports for. Defaults to
source.split(".")[0]whensourceis set; export-only mappings must set it explicitly.- Type:
str or None
- Subclassing registers the mapping automatically
- \* setting ``source`` registers it for :func:`import_object` under that
key; a second subclass reusing the same
sourceraisesTypeErrorat class-definition time.
- \* overriding :meth:`export_model` registers it for :func:`export_object`
under
(library, target); overriding without settingtargetraisesTypeError, overriding without a resolvablelibrary(nosourceto default it from) raisesTypeError, and a second subclass reusing the same(library, target)pair raisesTypeErrornaming both classes.
- The abstract base itself (``source is None`` and no ``export_model``
- override) registers nothing.
- import_model(obj, **opts)[source]¶
Convert third-party object obj into a quchip device.
Override to support import. The base implementation raises
NotImplementedError.
- quchip.interop.base.import_object(obj, **opts)[source]¶
Import third-party obj into a quchip device via 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 the skeleton for authoring a newModelMapping.- Parameters:
- 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:
- Return type: