transpile_result
¶
Provides a class to hold the results of quantum circuit transpilation.
The TranspileResult class holds the transpiled program, statistical information
before and after transpilation, and the mapping between virtual and physical (qu)bits.
This object is returned as the return value of the transpile() method in Tranqu.
Example
The following example demonstrates how to access the statistical information and virtual-physical qubit mapping of a transpile result.
>>> from tranqu import Tranqu
>>> from qiskit import QuantumCircuit
>>> tranqu = Tranqu()
>>> circuit = QuantumCircuit(2)
>>> circuit.swap(0, 1)
>>> result = tranqu.transpile(circuit, program_lib="qiskit",
transpiler_lib="qiskit",
transpiler_options={"basis_gates": ["cx"],
"coupling_map": [[0, 1], [1, 0]]})
>>> print(result.stats.after.n_gates)
3
>>> print(result.virtual_physical_mapping.qubit_mapping)
{0: 0, 1: 1}
You can obtain the transpiled program from TranspileResult:
transpile_result.transpiled_program: The transpiled program
You can also obtain the following statistical information:
transpile_result.stats.before.n_qubits: Number of qubits in the circuit before transpilationtranspile_result.stats.before.n_gates_1q: Number of 1-qubit gates before transpilationtranspile_result.stats.before.n_gates_2q: Number of 2-qubit gates before transpilationtranspile_result.stats.before.depth: Depth of the circuit before transpilationtranspile_result.stats.after.n_qubits: Number of qubits in the circuit after transpilationtranspile_result.stats.after.n_gates_1q: Number of 1-qubit gates after transpilationtranspile_result.stats.after.n_gates_2q: Number of 2-qubit gates after transpilationtranspile_result.stats.after.depth: Depth of the circuit after transpilation
You can also obtain the virtual-physical mapping information for qubits and classical bits:
transpile_result.virtual_physical_mapping.qubit_mapping: Mapping between virtual and physical qubitstranspile_result.virtual_physical_mapping.bit_mapping: Mapping between virtual and physical classical bits
NestedDictAccessor
¶
NestedDictAccessor(d: dict, stop_keys: set[str] | None = None)
A utility class for accessing nested dictionary attributes.
This class allows for easy access to nested dictionary attributes using dot notation. If a value in the dictionary is itself a dictionary, and the key is not in the specified stop keys, it returns another NestedDictAccessor instance for further nested access.
Parameters:
-
d(dict) –The dictionary to be accessed.
-
stop_keys(set[str] | None, default:None) –A set of keys where nested access should stop. If None, all keys are accessible.
Raises:
-
AttributeError–If an attribute name is not found in the dictionary.
items
¶
items() -> ItemsView[Any, Any]
Return an iterator over the (key, value) pairs of the dictionary.
Returns:
-
Iterator(ItemsView[Any, Any]) –A view over (key, value) pairs.
keys
¶
keys() -> KeysView[Any]
Return an iterator over the keys of the dictionary.
Returns:
-
KeysView[Any]–KeysView[Any]: A view over the keys.
values
¶
values() -> ValuesView[Any]
Return an iterator over the values of the dictionary.
Returns:
-
ValuesView[Any]–ValuesView[Any]: A view over the values.
TranspileResult
¶
TranspileResult(transpiled_program: Any, stats: dict[str, dict[str, int]], virtual_physical_mapping: dict[str, dict[int, int]])
Hold transpilation results.
Parameters:
-
transpiled_program(Any) –The quantum program after transpilation.
-
stats(dict[str, dict[str, int]]) –Statistical information before and after transpilation.
-
virtual_physical_mapping(dict[str, dict[int, int]]) –Mapping between virtual quantum bits and physical quantum bits.
to_dict
¶
to_dict() -> dict[str, Any]
Convert the TranspileResult to a dictionary.
Returns:
-
dict[str, Any]–dict[str, Any]: A dictionary representation of the TranspileResult,
-
dict[str, Any]–containing the statistical information and the virtual-physical
-
dict[str, Any]–qubit and bit mappings.