loqs.backends.reps.conversion¶
Attributes¶
| Name | Type | Value | Doc |
|---|---|---|---|
T |
TypeVar |
TypeVar('T', bound='OperationRep') |
TypeVar for the convert() function's generic return type. |
STANDARD_GATE_UNITARIES |
dict[str, NDArray] |
{'I': _I, 'X': _X, 'Y': _Y, 'Z': _Z, 'H': _H, 'S': _S, 'S_DAG': _S_DAG, 'CX': _CX, 'CZ': _CZ} |
Well-known single/two-qubit gate unitaries, keyed by generic name. Reused internally to build the N-qubit Pauli basis ( X/Y/Z/I) that this module's own Unitary<->PTM/Kraus<->PTM/Choi-decomposition math is built on, and exposed publicly so callers needing a small, fixed set of standard gates (e.g. example codepacks constructing an ideal noise model) have one source of truth instead of hand-copying these matrices again. |
Functions¶
convert ¶
convert(source: object, target: type[T] | Sequence[type[T]], qubits: str | int | Sequence[str | int] | None = None, **kwargs) -> T
Convert source (a raw payload or an OperationRep) to target.
- If
sourcealready is (or is an instance of)target, return it. - Else try constructing each entry of
targetdirectly fromsource, in order; return the first that succeeds. - Else resolve
source's unique concrete starting class and hop through_CONVERTERSto the closest target. A raw payload matching more than one concrete class is never guessed at here -- construct the intended representation explicitly instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
object
|
A raw, unwrapped payload, or an already-constructed
|
required |
target
|
type[T] | Sequence[type[T]]
|
The desired class, or a priority-ordered sequence of candidates. |
required |
qubits
|
str | int | Sequence[str | int] | None
|
Qubit label(s) this operation acts upon, if known, else |
None
|
**kwargs
|
Forwarded to whichever candidate class's constructor accepts them
(e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
T
|
The converted (or passed-through) representation. |
Raises:
| Type | Description |
|---|---|
RepConstructionError
|
If |
reachable_reps
cached
¶
reachable_reps(sources: tuple[type[OperationRep], ...]) -> tuple[type[OperationRep], ...]
sources, then every other concrete rep class convert can reach
from one of them, in _ALL_CONCRETE_REPS order.