TranslateParameterizedGates¶
- class qiskit.transpiler.passes.TranslateParameterizedGates(*args, **kwargs)[source]¶
Bases:
TransformationPass
Translate parameterized gates to a supported basis set.
Once a parameterized instruction is found that is not in the
supported_gates
list, the instruction is decomposed one level and the parameterized sub-blocks are recursively decomposed. The recursion is stopped once all parameterized gates are insupported_gates
, or if a gate has no definition and a translation to the basis is attempted (this might happen e.g. for theUGate
if it’s not in the specified gate list).Example
The following, multiply nested circuit:
from qiskit.circuit import QuantumCircuit, ParameterVector from qiskit.transpiler.passes import TranslateParameterizedGates x = ParameterVector("x", 4) block1 = QuantumCircuit(1) block1.rx(x[0], 0) sub_block = QuantumCircuit(2) sub_block.cx(0, 1) sub_block.rz(x[2], 0) block2 = QuantumCircuit(2) block2.ry(x[1], 0) block2.append(sub_block.to_gate(), [0, 1]) block3 = QuantumCircuit(3) block3.ccx(0, 1, 2) circuit = QuantumCircuit(3) circuit.append(block1.to_gate(), [1]) circuit.append(block2.to_gate(), [0, 1]) circuit.append(block3.to_gate(), [0, 1, 2]) circuit.cry(x[3], 0, 2) supported_gates = ["rx", "ry", "rz", "cp", "crx", "cry", "crz"] unrolled = TranslateParameterizedGates(supported_gates)(circuit)
is decomposed to:
┌──────────┐ ┌──────────┐┌─────────────┐ q_0: ┤ Ry(x[1]) ├──■──┤ Rz(x[2]) ├┤0 ├─────■────── ├──────────┤┌─┴─┐└──────────┘│ │ │ q_1: ┤ Rx(x[0]) ├┤ X ├────────────┤1 circuit-92 ├─────┼────── └──────────┘└───┘ │ │┌────┴─────┐ q_2: ─────────────────────────────┤2 ├┤ Ry(x[3]) ├ └─────────────┘└──────────┘
- Parameters:
supported_gates – A list of suppported basis gates specified as string. If
None
, atarget
must be provided.equivalence_library – The equivalence library to translate the gates. Defaults to the equivalence library of all Qiskit standard gates.
target – A
Target
containing the supported operations. IfNone
,supported_gates
must be set. Note that this argument takes precedence oversupported_gates
, if both are set.
- Raises:
ValueError – If neither of
supported_gates
andtarget
are passed.
Attributes
- is_analysis_pass¶
Check if the pass is an analysis pass.
If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write the results of that analysis in the property set. Modifications on the DAG are not allowed by this kind of pass.
- is_transformation_pass¶
Check if the pass is a transformation pass.
If the pass is a TransformationPass, that means that the pass can manipulate the DAG, but cannot modify the property set (but it can be read).
Methods
- execute(passmanager_ir, state, callback=None)¶
Execute optimization task for input Qiskit IR.
- Parameters:
passmanager_ir (Any) – Qiskit IR to optimize.
state (PassManagerState) – State associated with workflow execution by the pass manager itself.
callback (Callable | None) – A callback function which is caller per execution of optimization task.
- Returns:
Optimized Qiskit IR and state of the workflow.
- Return type:
tuple[Any, qiskit.passmanager.compilation_status.PassManagerState]
- run(dag)[source]¶
Run the transpiler pass.
- Parameters:
dag (DAGCircuit) – The DAG circuit in which the parameterized gates should be unrolled.
- Returns:
A DAG where the parameterized gates have been unrolled.
- Raises:
QiskitError – If the circuit cannot be unrolled.
- Return type:
- update_status(state, run_state)¶
Update workflow status.
- Parameters:
state (PassManagerState) – Pass manager state to update.
run_state (RunState) – Completion status of current task.
- Returns:
Updated pass manager state.
- Return type: