# CNOTDihedral

`qiskit.quantum_info.CNOTDihedral(data=None, num_qubits=None, validate=True)`

GitHub(opens in a new tab)

Bases: `BaseOperator`

, `AdjointMixin`

An N-qubit operator from the CNOT-Dihedral group.

The CNOT-Dihedral group is generated by the quantum gates,

`CXGate`

,`TGate`

, and`XGate`

.

RepresentationAn $N$-qubit CNOT-Dihedral operator is stored as an affine function and a phase polynomial, based on the convention in references [1, 2].

The affine function consists of an $N \times N$ invertible binary matrix, and an $N$ binary vector.

The phase polynomial is a polynomial of degree at most 3, in $N$ variables, whose coefficients are in the ring Z_8 with 8 elements.

`from qiskit import QuantumCircuit from qiskit.quantum_info import CNOTDihedral circ = QuantumCircuit(3) circ.cx(0, 1) circ.x(2) circ.t(1) circ.t(1) circ.t(1) elem = CNOTDihedral(circ) # Print the CNOTDihedral element print(elem)`

```
phase polynomial =
0 + 3*x_0 + 3*x_1 + 2*x_0*x_1
affine function =
(x_0,x_0 + x_1,x_2 + 1)
```

**Circuit Conversion**

CNOTDihedral operators can be initialized from circuits containing

onlythe following gates:`IGate`

,`XGate`

,`YGate`

,`ZGate`

,`TGate`

,`TdgGate`

`SGate`

,`SdgGate`

,`CXGate`

,`CZGate`

,`CSGate`

,`CSdgGate`

,`SwapGate`

,`CCZGate`

. They can be converted back into a`QuantumCircuit`

, or`Gate`

object using the`to_circuit()`

or`to_instruction()`

methods respectively. Note that this decomposition is not necessarily optimal in terms of number of gates if the number of qubits is more than two.CNOTDihedral operators can also be converted to

`Operator`

objects using the`to_operator()`

method. This is done via decomposing to a circuit, and then simulating the circuit as a unitary operator.

References:

- Shelly Garion and Andrew W. Cross,
Synthesis of CNOT-Dihedral circuits with optimal number of two qubit gates, Quantum 4(369), 2020(opens in a new tab)- Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta,
Scalable randomised benchmarking of non-Clifford gates, npj Quantum Inf 2, 16012 (2016).

Initialize a CNOTDihedral operator object.

**Parameters**

**data**(*CNOTDihedral**or**QuantumCircuit**or**Instruction*) – Optional, operator to initialize.**num_qubits**(*int*(opens in a new tab)) – Optional, initialize an empty CNOTDihedral operator.**validate**(*bool*(opens in a new tab)) – if True, validates the CNOTDihedral element.

**Raises**

**QiskitError**– if the type is invalid.**QiskitError**– if validate=True and the CNOTDihedral element is invalid.

## Attributes

### dim

Return tuple (input_shape, output_shape).

### name

Unique string identifier for operation type.

### num_clbits

Number of classical bits.

### num_qubits

Return the number of qubits if a N-qubit operator or None otherwise.

### qargs

Return the qargs for the operator.

## Methods

### adjoint

`adjoint()`

GitHub(opens in a new tab)

Return the adjoint of the Operator.

### compose

`compose(other, qargs=None, front=False)`

GitHub(opens in a new tab)

Return the operator composition with another CNOTDihedral.

**Parameters**

**other**(*CNOTDihedral*) – a CNOTDihedral object.**qargs**(*list*(opens in a new tab)*or None*) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).**front**(*bool*(opens in a new tab)) – If True compose using right operator multiplication, instead of left multiplication [default: False].

**Returns**

The composed CNOTDihedral.

**Return type**

**Raises**

**QiskitError** – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.

Composition (`&`

) by default is defined as left matrix multiplication for matrix operators, while `@`

(equivalent to `dot()`

) is defined as right matrix multiplication. That is that `A & B == A.compose(B)`

is equivalent to `B @ A == B.dot(A)`

when `A`

and `B`

are of the same type.

Setting the `front=True`

kwarg changes this to right matrix multiplication and is equivalent to the `dot()`

method `A.dot(B) == A.compose(B, front=True)`

.

### conjugate

`conjugate()`

GitHub(opens in a new tab)

Return the conjugate of the CNOTDihedral.

### copy

`copy()`

GitHub(opens in a new tab)

Make a deep copy of current operator.

### dot

`dot(other, qargs=None)`

GitHub(opens in a new tab)

Return the right multiplied operator self * other.

**Parameters**

**other**(*Operator*) – an operator object.**qargs**(*list*(opens in a new tab)*or None*) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).

**Returns**

The right matrix multiplied Operator.

**Return type**

The dot product can be obtained using the `@`

binary operator. Hence `a.dot(b)`

is equivalent to `a @ b`

.

### expand

`expand(other)`

GitHub(opens in a new tab)

Return the reverse-order tensor product with another CNOTDihedral.

**Parameters**

**other** (*CNOTDihedral*) – a CNOTDihedral object.

**Returns**

**the tensor product $b \otimes a$, where $a$**

is the current CNOTDihedral, and $b$ is the other CNOTDihedral.

**Return type**

### input_dims

`input_dims(qargs=None)`

GitHub(opens in a new tab)

Return tuple of input dimension for specified subsystems.

### output_dims

`output_dims(qargs=None)`

GitHub(opens in a new tab)

Return tuple of output dimension for specified subsystems.

### power

`power(n)`

GitHub(opens in a new tab)

Return the compose of a operator with itself n times.

**Parameters**

**n** (*int*(opens in a new tab)) – the number of times to compose with self (n>0).

**Returns**

the n-times composed operator.

**Return type**

**Raises**

**QiskitError** – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.

### reshape

`reshape(input_dims=None, output_dims=None, num_qubits=None)`

GitHub(opens in a new tab)

Return a shallow copy with reshaped input and output subsystem dimensions.

**Parameters**

**input_dims**(*None or**tuple*(opens in a new tab)) – new subsystem input dimensions. If None the original input dims will be preserved [Default: None].**output_dims**(*None or**tuple*(opens in a new tab)) – new subsystem output dimensions. If None the original output dims will be preserved [Default: None].**num_qubits**(*None or**int*(opens in a new tab)) – reshape to an N-qubit operator [Default: None].

**Returns**

returns self with reshaped input and output dimensions.

**Return type**

BaseOperator

**Raises**

**QiskitError** – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.

### tensor

`tensor(other)`

GitHub(opens in a new tab)

Return the tensor product with another CNOTDihedral.

**Parameters**

**other** (*CNOTDihedral*) – a CNOTDihedral object.

**Returns**

**the tensor product $a \otimes b$, where $a$**

is the current CNOTDihedral, and $b$ is the other CNOTDihedral.

**Return type**

The tensor product can be obtained using the `^`

binary operator. Hence `a.tensor(b)`

is equivalent to `a ^ b`

.

### to_circuit

`to_circuit()`

GitHub(opens in a new tab)

Return a QuantumCircuit implementing the CNOT-Dihedral element.

**Returns**

a circuit implementation of the CNOTDihedral object.

**Return type**

**References**

- Shelly Garion and Andrew W. Cross,
*Synthesis of CNOT-Dihedral circuits with optimal number of two qubit gates*, Quantum 4(369), 2020(opens in a new tab) - Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta,
*Scalable randomised benchmarking of non-Clifford gates*, npj Quantum Inf 2, 16012 (2016).

### to_instruction

`to_instruction()`

GitHub(opens in a new tab)

Return a Gate instruction implementing the CNOTDihedral object.

### to_matrix

`to_matrix()`

GitHub(opens in a new tab)

Convert operator to Numpy matrix.

### to_operator

`to_operator()`

GitHub(opens in a new tab)

### transpose

`transpose()`

GitHub(opens in a new tab)

Return the transpose of the CNOTDihedral.