qiskit-documentation/docs/api/qiskit/0.46/qiskit.circuit.AnnotatedOpe...

79 lines
3.5 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: AnnotatedOperation
description: API reference for qiskit.circuit.AnnotatedOperation
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.circuit.AnnotatedOperation
---
# AnnotatedOperation
<Class id="qiskit.circuit.AnnotatedOperation" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.46/qiskit/circuit/annotated_operation.py" signature="qiskit.circuit.AnnotatedOperation(base_op, modifiers)" modifiers="class">
Bases: [`Operation`](qiskit.circuit.Operation "qiskit.circuit.operation.Operation")
Annotated operation.
Create a new AnnotatedOperation.
An “annotated operation” allows to add a list of modifiers to the “base” operation. For now, the only supported modifiers are of types [`InverseModifier`](qiskit.circuit.InverseModifier "qiskit.circuit.InverseModifier"), [`ControlModifier`](qiskit.circuit.ControlModifier "qiskit.circuit.ControlModifier") and [`PowerModifier`](qiskit.circuit.PowerModifier "qiskit.circuit.PowerModifier").
An annotated operation can be viewed as an extension of [`ControlledGate`](qiskit.circuit.ControlledGate "qiskit.circuit.ControlledGate") (which also allows adding control to the base operation). However, an important difference is that the circuit definition of an annotated operation is not constructed when the operation is declared, and instead happens during transpilation, specifically during the [`HighLevelSynthesis`](qiskit.transpiler.passes.HighLevelSynthesis "qiskit.transpiler.passes.HighLevelSynthesis") transpiler pass.
An annotated operation can be also viewed as a “higher-level” or “more abstract” object that can be added to a quantum circuit. This enables writing transpiler optimization passes that make use of this higher-level representation, for instance removing a gate that is immediately followed by its inverse.
**Parameters**
* **base\_op** ([*Operation*](qiskit.circuit.Operation "qiskit.circuit.operation.Operation")) base operation being modified
* **modifiers** (*Modifier |* [*List*](https://docs.python.org/3/library/typing.html#typing.List "(in Python v3.12)")*\[Modifier]*) ordered list of modifiers. Supported modifiers include `InverseModifier`, `ControlModifier` and `PowerModifier`.
Examples:
```python
op1 = AnnotatedOperation(SGate(), [InverseModifier(), ControlModifier(2)])
op2_inner = AnnotatedGate(SGate(), InverseModifier())
op2 = AnnotatedGate(op2_inner, ControlModifier(2))
```
Both op1 and op2 are semantically equivalent to an `SGate()` which is first inverted and then controlled by 2 qubits.
## Attributes
### name
<Attribute id="qiskit.circuit.AnnotatedOperation.name">
Unique string identifier for operation type.
</Attribute>
### num\_clbits
<Attribute id="qiskit.circuit.AnnotatedOperation.num_clbits">
Number of classical bits.
</Attribute>
### num\_qubits
<Attribute id="qiskit.circuit.AnnotatedOperation.num_qubits">
Number of qubits.
</Attribute>
## Methods
### copy
<Function id="qiskit.circuit.AnnotatedOperation.copy" signature="copy()">
Return a copy of the [`AnnotatedOperation`](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation").
**Return type**
[*AnnotatedOperation*](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.annotated_operation.AnnotatedOperation")
</Function>
### to\_matrix
<Function id="qiskit.circuit.AnnotatedOperation.to_matrix" signature="to_matrix()">
Return a matrix representation (allowing to construct Operator).
</Function>
</Class>