---
title: AnnotatedOperation (latest version)
description: API reference for qiskit.circuit.AnnotatedOperation in the latest version of qiskit
source: https://quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.circuit.AnnotatedOperation
---

# AnnotatedOperation

*class* `qiskit.circuit.AnnotatedOperation(base_op, modifiers)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L59-L241)

Bases: [`Operation`](/docs/api/qiskit/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`](/docs/api/qiskit/circuit#qiskit.circuit.InverseModifier "qiskit.circuit.InverseModifier"), [`ControlModifier`](/docs/api/qiskit/circuit#qiskit.circuit.ControlModifier "qiskit.circuit.ControlModifier") and [`PowerModifier`](/docs/api/qiskit/circuit#qiskit.circuit.PowerModifier "qiskit.circuit.PowerModifier").

An annotated operation can be viewed as an extension of [`ControlledGate`](/docs/api/qiskit/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`](/docs/api/qiskit/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*](/docs/api/qiskit/qiskit.circuit.Operation "qiskit.circuit.Operation")) – base operation being modified
- **modifiers** (*Modifier |* [*list*](https://docs.python.org/3/library/stdtypes.html#list)*\[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

Unique string identifier for operation type.

### num\_clbits

Number of classical bits.

### num\_qubits

Number of qubits.

### params

The params of the underlying base operation.

### base\_op

The base operation that the modifiers in this annotated operation apply to.

### modifiers

Ordered sequence of the modifiers to apply to [`base_op`](#qiskit.circuit.AnnotatedOperation.base_op "qiskit.circuit.AnnotatedOperation.base_op"). The modifiers are applied in order from lowest index to highest index.

## Methods

### control

`control(num_ctrl_qubits=1, label=None, ctrl_state=None, annotated=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L158-L185)

Return the controlled version of itself.

Implemented as [`AnnotatedOperation`](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation"), regardless of the value of `annotated`.

**Parameters**

- **num\_ctrl\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int)) – Number of controls to add. Defaults to `1`.
- **label** ([*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – Ignored.
- **ctrl\_state** ([*int*](https://docs.python.org/3/library/functions.html#int)  *|*[*str*](https://docs.python.org/3/library/stdtypes.html#str) *| None*) – The control state of the gate, specified either as an integer or a bitstring (e.g. `"110"`). If `None`, defaults to the all-ones state `2**num_ctrl_qubits - 1`.
- **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool) *| None*) – Ignored.

**Returns**

A controlled version of the given operation.

**Return type**

[*AnnotatedOperation*](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.annotated_operation.AnnotatedOperation")

### copy

`copy()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L133-L135)

Return a copy of the [`AnnotatedOperation`](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation").

**Return type**

[*AnnotatedOperation*](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.annotated_operation.AnnotatedOperation")

### inverse

`inverse(annotated=True)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L187-L202)

Return the inverse version of itself.

Implemented as an annotated operation, see [`AnnotatedOperation`](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation").

**Parameters**

**annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – ignored (used for consistency with other inverse methods)

**Returns**

Inverse version of the given operation.

### power

`power(exponent, annotated=False)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L204-L220)

Raise this gate to the power of `exponent`.

Implemented as an annotated operation, see [`AnnotatedOperation`](#qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation").

**Parameters**

- **exponent** ([*float*](https://docs.python.org/3/library/functions.html#float)) – the power to raise the gate to
- **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) – ignored (used for consistency with other power methods)

**Returns**

An operation implementing `gate^exponent`

### to\_matrix

`to_matrix()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L137-L156)

Return a matrix representation (allowing to construct Operator).

### validate\_parameter

`validate_parameter(parameter)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/annotated_operation.py#L236-L241)

Validate a parameter for the underlying base operation.

**Parameters**

**parameter** ([*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression")  *|*[*float*](https://docs.python.org/3/library/functions.html#float))

**Return type**

[*ParameterExpression*](/docs/api/qiskit/qiskit.circuit.ParameterExpression "qiskit._accelerate.circuit.ParameterExpression") | [float](https://docs.python.org/3/library/functions.html#float)
