165 lines
7.5 KiB
Plaintext
165 lines
7.5 KiB
Plaintext
---
|
||
title: TranslateParameterizedGates (v1.2)
|
||
description: API reference for qiskit.transpiler.passes.TranslateParameterizedGates in qiskit v1.2
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.transpiler.passes.TranslateParameterizedGates
|
||
---
|
||
|
||
# TranslateParameterizedGates
|
||
|
||
<Class id="qiskit.transpiler.passes.TranslateParameterizedGates" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passes/basis/translate_parameterized.py#L27-L149" signature="qiskit.transpiler.passes.TranslateParameterizedGates(*args, **kwargs)" modifiers="class">
|
||
Bases: [`TransformationPass`](qiskit.transpiler.TransformationPass "qiskit.transpiler.basepasses.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 in `supported_gates`, or if a gate has no definition and a translation to the basis is attempted (this might happen e.g. for the `UGate` if it’s not in the specified gate list).
|
||
|
||
**Example**
|
||
|
||
The following, multiply nested circuit:
|
||
|
||
```python
|
||
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:
|
||
|
||
```python
|
||
┌──────────┐ ┌──────────┐┌─────────────┐
|
||
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`, a `target` 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`](qiskit.transpiler.Target "qiskit.transpiler.Target") containing the supported operations. If `None`, `supported_gates` must be set. Note that this argument takes precedence over `supported_gates`, if both are set.
|
||
|
||
**Raises**
|
||
|
||
[**ValueError**](https://docs.python.org/3/library/exceptions.html#ValueError "(in Python v3.13)") – If neither of `supported_gates` and `target` are passed.
|
||
|
||
## Attributes
|
||
|
||
### is\_analysis\_pass
|
||
|
||
<Attribute id="qiskit.transpiler.passes.TranslateParameterizedGates.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.
|
||
</Attribute>
|
||
|
||
### is\_transformation\_pass
|
||
|
||
<Attribute id="qiskit.transpiler.passes.TranslateParameterizedGates.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).
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### execute
|
||
|
||
<Function id="qiskit.transpiler.passes.TranslateParameterizedGates.execute" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/basepasses.py#L189-L211" signature="execute(passmanager_ir, state, callback=None)">
|
||
Execute optimization task for input Qiskit IR.
|
||
|
||
**Parameters**
|
||
|
||
* **passmanager\_ir** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.13)")) – Qiskit IR to optimize.
|
||
* **state** ([*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – State associated with workflow execution by the pass manager itself.
|
||
* **callback** ([*Callable*](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable "(in Python v3.13)") *| None*) – A callback function which is caller per execution of optimization task.
|
||
|
||
**Returns**
|
||
|
||
Optimized Qiskit IR and state of the workflow.
|
||
|
||
**Return type**
|
||
|
||
[tuple](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.13)")\[[*Any*](https://docs.python.org/3/library/typing.html#typing.Any "(in Python v3.13)"), [qiskit.passmanager.compilation\_status.PassManagerState](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")]
|
||
</Function>
|
||
|
||
### name
|
||
|
||
<Function id="qiskit.transpiler.passes.TranslateParameterizedGates.name" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/passmanager/base_tasks.py#L68-L70" signature="name()">
|
||
Name of the pass.
|
||
|
||
**Return type**
|
||
|
||
[str](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")
|
||
</Function>
|
||
|
||
### run
|
||
|
||
<Function id="qiskit.transpiler.passes.TranslateParameterizedGates.run" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/passes/basis/translate_parameterized.py#L117-L149" signature="run(dag)">
|
||
Run the transpiler pass.
|
||
|
||
**Parameters**
|
||
|
||
**dag** ([*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.dagcircuit.DAGCircuit")) – The DAG circuit in which the parameterized gates should be unrolled.
|
||
|
||
**Returns**
|
||
|
||
A DAG where the parameterized gates have been unrolled.
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – If the circuit cannot be unrolled.
|
||
|
||
**Return type**
|
||
|
||
[*DAGCircuit*](qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.dagcircuit.DAGCircuit")
|
||
</Function>
|
||
|
||
### update\_status
|
||
|
||
<Function id="qiskit.transpiler.passes.TranslateParameterizedGates.update_status" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/transpiler/basepasses.py#L213-L221" signature="update_status(state, run_state)">
|
||
Update workflow status.
|
||
|
||
**Parameters**
|
||
|
||
* **state** ([*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")) – Pass manager state to update.
|
||
* **run\_state** (*RunState*) – Completion status of current task.
|
||
|
||
**Returns**
|
||
|
||
Updated pass manager state.
|
||
|
||
**Return type**
|
||
|
||
[*PassManagerState*](qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")
|
||
</Function>
|
||
</Class>
|
||
|