AnnotatedOperation
class qiskit.circuit.AnnotatedOperation(base_op, modifiers)
Bases: 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
, ControlModifier
and PowerModifier
.
An annotated operation can be viewed as an extension of 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
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) – base operation being modified
- modifiers (Union[Modifier, List[Modifier]]) – ordered list of modifiers. Supported modifiers include
InverseModifier
,ControlModifier
andPowerModifier
.
Examples:
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 applies to.
modifiers
Ordered sequence of the modifiers to apply to 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=True)
Return the controlled version of itself.
Implemented as an annotated operation, see AnnotatedOperation
.
Parameters
- num_ctrl_qubits (int) – number of controls to add to gate (default:
1
) - label (str | None) – ignored (used for consistency with other control methods)
- ctrl_state (int |str | None) – The control state in decimal or as a bitstring (e.g.
'111'
). IfNone
, use2**num_ctrl_qubits-1
. - annotated (bool) – ignored (used for consistency with other control methods)
Returns
Controlled version of the given operation.
Return type
copy
inverse
inverse(annotated=True)
Return the inverse version of itself.
Implemented as an annotated operation, see AnnotatedOperation
.
Parameters
annotated (bool) – ignored (used for consistency with other inverse methods)
Returns
Inverse version of the given operation.
power
power(exponent, annotated=False)
Raise this gate to the power of exponent
.
Implemented as an annotated operation, see AnnotatedOperation
.
Parameters
- exponent (float) – the power to raise the gate to
- annotated (bool) – ignored (used for consistency with other power methods)
Returns
An operation implementing gate^exponent
to_matrix
validate_parameter
validate_parameter(parameter)
Validate a parameter for the underlying base operation.
Parameters
parameter (ParameterExpression |float) –
Return type