interop Package
Classes
| PeakUsageGreedyQubitManager |
A qubit manager tracking compute and memory qubits separately. It consists of two independent qubit managers for each qubit type. Each manager
uses greedy allocation strategy from Qubits of one type, after freed, cannot be reused as qubits of different type. Therefore, peak qubit count is equal to sum of peak qubit counts for each type. Initialize the PeakUsageGreedyQubitManager. |
| PopBlock |
Signals the end of the current repeated block in the trace. |
| PushBlock |
Signals the start of a repeated block in the trace. |
| ReadFromMemoryGate |
Moves qubit states from MEMORY register to COMPUTE register. Assumes COMPUTE qubits are prepared in 0 state. Leaves MEMORY qubits in 0 state. Initializes ReadFromMemoryGate. |
| TypedQubit |
Qubit with type. Initializes typed qubit. |
| WriteToMemoryGate |
Moves qubit states from COMPUTE register to MEMORY register. Assumes MEMORY qubits are prepared in 0 state. Leaves COMPUTE qubits in 0 state. Initializes WriteToMemoryGate. |
Enums
| QubitType |
Qubit type. Each logical qubit can be either a compute or memory qubit. Compute qubits can be used normally. Memory qubits have a restriction that gates cannot be applied to them. The only allowed operations on memory qubits are reads/writes, where state is moved from memory to compute gate or from compute to memory gate. We assume that when error correction is applied, memory qubits are encoded with a more efficient error correction scheme requiring less resources, but not allowing gate application (e.g. Yoked surface codes, https://arxiv.org/abs/2312.04522). |
Functions
assert_qubits_type
Asserts that qubits have specified type, but only if they are TypedQubits.
assert_qubits_type(qs: Sequence[Qid], qubit_type: QubitType) -> None
Parameters
| Name | Description |
|---|---|
|
qs
Required
|
|
|
qubit_type
Required
|
|
read_from_memory
Operation to read qubits from memory.
read_from_memory(memory_qubits: Sequence[Qid], compute_qubits: Sequence[Qid]) -> Operation
Parameters
| Name | Description |
|---|---|
|
memory_qubits
Required
|
|
|
compute_qubits
Required
|
|
trace_from_cirq
Convert a Cirq circuit into a resource estimation Trace.
Iterates through all moments and operations in the circuit, converting
each gate into trace operations. Gates with a _to_trace method are
converted directly; others are recursively decomposed via Cirq's
_decompose_with_context_ or _decompose_ protocols.
trace_from_cirq(circuit: cirq.CIRCUIT_LIKE, *, classical_control_probability: float = 0.5, rotation_threshold: float = 1e-06, track_memory_qubits: bool = True) -> Trace
Parameters
| Name | Description |
|---|---|
|
circuit
Required
|
The Cirq circuit to convert. |
|
classical_control_probability
Required
|
Probability that a classically controlled operation is included in the trace. Defaults to 0.5. |
|
rotation_threshold
Required
|
Rotation exponents with absolute value below this threshold are treated as identity and omitted from the trace. This applies to single-qubit rotations (RX, RY, RZ) as well as to the rotation components of controlled-Z decompositions. Defaults to 1e-6. |
|
track_memory_qubits
Required
|
When True, memory qubits are tracked separately from compute qubits. When False, all qubits are treated as compute qubits. Also, if True, read-from-memory and write-to-memory instructions are preserved in the trace, otherwise, they are decompsed into SWAP and RESET instructions. Defaults to True. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
classical_control_probability
|
Default value: 0.5
|
|
rotation_threshold
|
Default value: 1e-06
|
|
track_memory_qubits
|
Default value: True
|
Returns
| Type | Description |
|---|---|
|
A Trace representing an execution profile of the circuit. |
trace_from_entry_expr
Convert a Q# entry expression into a resource-estimation Trace.
Evaluates the entry expression to obtain logical counts, then builds a trace containing the corresponding quantum operations.
trace_from_entry_expr(entry_expr: str | Callable | LogicalCounts, *args) -> Trace
Parameters
| Name | Description |
|---|---|
|
entry_expr
Required
|
<xref:<xref:qdk.qre.interop.str | Callable | LogicalCounts>>
A Q# entry expression string, a callable, or pre-computed logical counts. |
|
*args
Required
|
The arguments to pass to the callable, if one is provided. |
Returns
| Type | Description |
|---|---|
|
A trace representing the resource profile of the program. |
trace_from_entry_expr_cached
Convert a Q# entry expression into a Trace, with optional caching.
If cache_path is provided and exists, the trace is loaded from disk.
Otherwise, the trace is computed via trace_from_entry_expr and
optionally written to cache_path.
trace_from_entry_expr_cached(entry_expr: str | Callable | LogicalCounts, cache_path: Path | None, *args) -> Trace
Parameters
| Name | Description |
|---|---|
|
entry_expr
Required
|
<xref:<xref:qdk.qre.interop.str | Callable | LogicalCounts>>
A Q# entry expression string, a callable, or pre-computed logical counts. |
|
cache_path
Required
|
<xref:Optional>[<xref:Path>]
Path for reading/writing the cached trace. If None, caching is disabled. |
Returns
| Type | Description |
|---|---|
|
A trace representing the resource profile of the program. |
trace_from_qir
Convert a QIR program into a resource-estimation Trace.
Parses the QIR module, extracts quantum gates, and builds a Trace that can be used for resource estimation. Conditional branches are resolved by always following the false path (assuming measurement results are Zero).
trace_from_qir(input: str | bytes) -> Trace
Parameters
| Name | Description |
|---|---|
|
input
Required
|
QIR input as LLVM IR text (str) or bitcode (bytes). |
Returns
| Type | Description |
|---|---|
|
A Trace containing the quantum operations from the QIR program. |
write_to_memory
Operation to write qubits to memory.
write_to_memory(memory_qubits: Sequence[Qid], compute_qubits: Sequence[Qid]) -> Operation
Parameters
| Name | Description |
|---|---|
|
memory_qubits
Required
|
|
|
compute_qubits
Required
|
|