qunicorn_core.core.transpiler.circuit_transpiler module
- class qunicorn_core.core.transpiler.circuit_transpiler.CircuitTranspiler
Bases:
objectBase class for all circuit transpilers.
To create a new transpiler, inherit from this class and implement the
CircuitTranspiler.transpile_circuit()method.Example:
class DemoTranspiler(CircuitTranspiler, source="source-format", target="target-format", cost=1): unsafe = False # set to True if transpilation may execute unsafe code def transpile_circuit(self, circuit: Any) -> Any: ...
- static get_known_formats() set[str]
Get all known formats (i.e., set(target_formats) + set(source_formats)).
- static get_transpilers(source: str) Sequence[CircuitTranspiler]
Get all transpilers registered for a specific source format.
- Raises:
KeyError: If the source format is not a known format.
- Returns:
Sequence[CircuitTranspiler]: all circuit transpilers registered for this source format (may be empty)
- static get_transpilers_limit_cost(source: str | Sequence[str], target: str, *, exclude: set[str | Type[CircuitTranspiler]] | None = None, exclude_formats: set[str] | None = None, exclude_unsafe: bool = False) Sequence[CircuitTranspiler]
Get a list of transpilers from source to target format using the transpiler cost.
- static get_transpilers_limit_depth(source: str | Sequence[str | tuple[str, int]], target: str, *, exclude: set[str | Type[CircuitTranspiler]] | None = None, exclude_formats: set[str] | None = None, exclude_unsafe: bool = False) Sequence[CircuitTranspiler]
Get a list of transpilers from source to target format using a constant cost of 1 for each step.
- exception qunicorn_core.core.transpiler.circuit_transpiler.TranspilationError(transpiler: CircuitTranspiler, circuit: Any, *args: object)
Bases:
ExceptionBase error for all transpilation failures.
- qunicorn_core.core.transpiler.circuit_transpiler.transpile_circuit(target: str, *circuit: tuple[str, Any, int], exclude: set[str | Type[CircuitTranspiler]] | None = None, exclude_formats: set[str] | None = None, exclude_unsafe: bool = False, visitor: Callable[[str, Any, int], None] | None = None) Any
Transpile a circuit available in one or more source formats to a specific target format.
- Args:
target (str): the target format for transpilation exclude (set[str | Type[CircuitTranspiler]], optional): exclude specific transpilers (by class, class name or qualified class name). exclude_formats (set[str], optional): exclude specific formats from transpilation. Applies to both source and target formats! exclude_unsafe (bool, optional): exclude unsafe transpilers from transpilation. Defaults to False. visitor (Callable[[str, Any, int], None]], optional): gets called for every translated circuit.
- Raises:
ValueError: If no circuit is provided or either the target format or all source formats are excluded by exclude_formats. KeyError: If no transpilation chain could be found to transpile the circuit to the target format. TranspilationError: If a transpilation step fails.
- Returns:
Any: The transpiled circuit (this may be one of the input circuits if the format matches the target format)