---
title: InverseCancellation (v2.4)
description: API reference for qiskit.transpiler.passes.InverseCancellation in qiskit v2.4
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/2.4/qiskit.transpiler.passes.InverseCancellation
---

# InverseCancellation

*class* `qiskit.transpiler.passes.InverseCancellation(*args, **kwargs)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/transpiler/passes/optimization/inverse_cancellation.py#L31-L142)

Bases: [`TransformationPass`](/docs/api/qiskit/2.4/qiskit.transpiler.TransformationPass "qiskit.transpiler.basepasses.TransformationPass")

Cancel specific Gates which are inverses of each other when they occur back-to- back.

Initialize InverseCancellation pass.

**Parameters**

- **gates\_to\_cancel** –

  List describing the gates to cancel. Each element of the list is either a single gate or a pair of gates. If a single gate, then it should be self-inverse. If a pair of gates, then the gates in the pair should be inverses of each other. If `None` a default list of self-inverse gates and a default list of inverse gate pairs will be used. The current default list of self-inverse gates is:

  > - [`CXGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CXGate "qiskit.circuit.library.CXGate")
  > - [`ECRGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.ECRGate "qiskit.circuit.library.ECRGate")
  > - [`CYGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CYGate "qiskit.circuit.library.CYGate")
  > - [`CZGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CZGate "qiskit.circuit.library.CZGate")
  > - [`XGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.XGate "qiskit.circuit.library.XGate")
  > - [`YGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.YGate "qiskit.circuit.library.YGate")
  > - [`ZGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.ZGate "qiskit.circuit.library.ZGate")
  > - [`HGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.HGate "qiskit.circuit.library.HGate")
  > - [`SwapGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate")
  > - [`CHGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CHGate "qiskit.circuit.library.CHGate")
  > - [`CCXGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CCXGate "qiskit.circuit.library.CCXGate")
  > - [`CCZGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CCZGate "qiskit.circuit.library.CCZGate")
  > - [`RCCXGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.RCCXGate "qiskit.circuit.library.RCCXGate")
  > - [`CSwapGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CSwapGate "qiskit.circuit.library.CSwapGate")
  > - [`C3XGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.C3XGate "qiskit.circuit.library.C3XGate")

  and the default list of inverse gate pairs is:

  > - [`TGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.TGate "qiskit.circuit.library.TGate") and [`TdgGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.TdgGate "qiskit.circuit.library.TdgGate")
  > - [`SGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.SGate "qiskit.circuit.library.SGate") and [`SdgGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.SdgGate "qiskit.circuit.library.SdgGate")
  > - [`SXGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.SXGate "qiskit.circuit.library.SXGate") and [`SXdgGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.SXdgGate "qiskit.circuit.library.SXdgGate")
  > - [`CSGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CSGate "qiskit.circuit.library.CSGate") and [`CSdgGate`](/docs/api/qiskit/2.4/qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate")

- **run\_default** – If set to true and `gates_to_cancel` is set to a list then in addition to the gates listed in `gates_to_cancel` the default list of gate inverses (the same as when `gates_to_cancel` is set to `None`) will be run. The order of evaluation is significant in how sequences of gates are cancelled and the default gates will be evaluated after the provided gates in `gates_to_cancel`. If `gates_to_cancel` is `None` this option has no impact.

**Raises**

[**TranspilerError**](/docs/api/qiskit/2.4/transpiler#qiskit.transpiler.TranspilerError "qiskit.transpiler.TranspilerError") – Input is not a self-inverse gate or a pair of inverse gates.

## 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

`execute(passmanager_ir, state, callback=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/transpiler/basepasses.py#L161-L180)

Execute optimization task for input Qiskit IR.

**Parameters**

- **passmanager\_ir** ([*Any*](https://docs.python.org/3/library/typing.html#typing.Any)) – Qiskit IR to optimize.
- **state** ([*PassManagerState*](/docs/api/qiskit/2.4/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) *| None*) – A callback function which is called 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)\[[*Any*](https://docs.python.org/3/library/typing.html#typing.Any), [*PassManagerState*](/docs/api/qiskit/2.4/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")]

### name

`name()`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/passmanager/base_tasks.py#L67-L69)

Name of the pass.

**Return type**

[str](https://docs.python.org/3/library/stdtypes.html#str)

### run

`run(dag)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/transpiler/passes/optimization/inverse_cancellation.py#L121-L142)

Run the InverseCancellation pass on dag.

**Parameters**

**dag** ([*DAGCircuit*](/docs/api/qiskit/2.4/qiskit.dagcircuit.DAGCircuit "qiskit._accelerate.circuit.DAGCircuit")) – the directed acyclic graph to run on.

**Returns**

Transformed DAG.

**Return type**

[DAGCircuit](/docs/api/qiskit/2.4/qiskit.dagcircuit.DAGCircuit "qiskit.dagcircuit.DAGCircuit")

### update\_status

`update_status(state, run_state)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.4/qiskit/transpiler/basepasses.py#L182-L190)

Update workflow status.

**Parameters**

- **state** ([*PassManagerState*](/docs/api/qiskit/2.4/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*](/docs/api/qiskit/2.4/qiskit.passmanager.PassManagerState "qiskit.passmanager.compilation_status.PassManagerState")
