328 lines
16 KiB
Plaintext
328 lines
16 KiB
Plaintext
---
|
||
title: CNOTDihedral
|
||
description: API reference for qiskit.quantum_info.CNOTDihedral
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.quantum_info.CNOTDihedral
|
||
---
|
||
|
||
# CNOTDihedral
|
||
|
||
<Class id="qiskit.quantum_info.CNOTDihedral" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L31-L505" signature="qiskit.quantum_info.CNOTDihedral(data=None, num_qubits=None, validate=True)" modifiers="class">
|
||
Bases: `BaseOperator`, `AdjointMixin`
|
||
|
||
An N-qubit operator from the CNOT-Dihedral group.
|
||
|
||
> The CNOT-Dihedral group is generated by the quantum gates, [`CXGate`](qiskit.circuit.library.CXGate "qiskit.circuit.library.CXGate"), [`TGate`](qiskit.circuit.library.TGate "qiskit.circuit.library.TGate"), and [`XGate`](qiskit.circuit.library.XGate "qiskit.circuit.library.XGate").
|
||
>
|
||
> **Representation**
|
||
>
|
||
> An $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.
|
||
>
|
||
> ```python
|
||
> 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)
|
||
> ```
|
||
|
||
```python
|
||
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 *only* the following gates: [`IGate`](qiskit.circuit.library.IGate "qiskit.circuit.library.IGate"), [`XGate`](qiskit.circuit.library.XGate "qiskit.circuit.library.XGate"), [`YGate`](qiskit.circuit.library.YGate "qiskit.circuit.library.YGate"), [`ZGate`](qiskit.circuit.library.ZGate "qiskit.circuit.library.ZGate"), [`TGate`](qiskit.circuit.library.TGate "qiskit.circuit.library.TGate"), [`TdgGate`](qiskit.circuit.library.TdgGate "qiskit.circuit.library.TdgGate") [`SGate`](qiskit.circuit.library.SGate "qiskit.circuit.library.SGate"), [`SdgGate`](qiskit.circuit.library.SdgGate "qiskit.circuit.library.SdgGate"), [`CXGate`](qiskit.circuit.library.CXGate "qiskit.circuit.library.CXGate"), [`CZGate`](qiskit.circuit.library.CZGate "qiskit.circuit.library.CZGate"), [`CSGate`](qiskit.circuit.library.CSGate "qiskit.circuit.library.CSGate"), [`CSdgGate`](qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate"), [`SwapGate`](qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate"), [`CCZGate`](qiskit.circuit.library.CCZGate "qiskit.circuit.library.CCZGate"). They can be converted back into a [`QuantumCircuit`](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit"), or [`Gate`](qiskit.circuit.Gate "qiskit.circuit.Gate") object using the [`to_circuit()`](#qiskit.quantum_info.CNOTDihedral.to_circuit "qiskit.quantum_info.CNOTDihedral.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`](qiskit.quantum_info.Operator "qiskit.quantum_info.Operator") objects using the [`to_operator()`](#qiskit.quantum_info.CNOTDihedral.to_operator "qiskit.quantum_info.CNOTDihedral.to_operator") method. This is done via decomposing to a circuit, and then simulating the circuit as a unitary operator.
|
||
>
|
||
> **References:**
|
||
>
|
||
> 1. Shelly Garion and Andrew W. Cross, *Synthesis of CNOT-Dihedral circuits with optimal number of two qubit gates*, [Quantum 4(369), 2020](https://quantum-journal.org/papers/q-2020-12-07-369/)
|
||
> 2. Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, *Scalable randomized benchmarking of non-Clifford gates*, npj Quantum Inf 2, 16012 (2016).
|
||
|
||
Initialize a CNOTDihedral operator object.
|
||
|
||
**Parameters**
|
||
|
||
* **data** ([*CNOTDihedral*](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral") *or*[*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") *or*[*Instruction*](qiskit.circuit.Instruction "qiskit.circuit.Instruction")) – Optional, operator to initialize.
|
||
* **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) – Optional, initialize an empty CNOTDihedral operator.
|
||
* **validate** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) – if True, validates the CNOTDihedral element.
|
||
|
||
**Raises**
|
||
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if the type is invalid.
|
||
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if validate=True and the CNOTDihedral element is invalid.
|
||
|
||
## Attributes
|
||
|
||
### dim
|
||
|
||
<Attribute id="qiskit.quantum_info.CNOTDihedral.dim">
|
||
Return tuple (input\_shape, output\_shape).
|
||
</Attribute>
|
||
|
||
### name
|
||
|
||
<Attribute id="qiskit.quantum_info.CNOTDihedral.name">
|
||
Unique string identifier for operation type.
|
||
</Attribute>
|
||
|
||
### num\_clbits
|
||
|
||
<Attribute id="qiskit.quantum_info.CNOTDihedral.num_clbits">
|
||
Number of classical bits.
|
||
</Attribute>
|
||
|
||
### num\_qubits
|
||
|
||
<Attribute id="qiskit.quantum_info.CNOTDihedral.num_qubits">
|
||
Return the number of qubits if a N-qubit operator or None otherwise.
|
||
</Attribute>
|
||
|
||
### qargs
|
||
|
||
<Attribute id="qiskit.quantum_info.CNOTDihedral.qargs">
|
||
Return the qargs for the operator.
|
||
</Attribute>
|
||
|
||
## Methods
|
||
|
||
### adjoint
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.adjoint" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L442-L445" signature="adjoint()">
|
||
Return the adjoint of the Operator.
|
||
</Function>
|
||
|
||
### compose
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.compose" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L374-L386" signature="compose(other, qargs=None, front=False)">
|
||
Return the operator composition with another CNOTDihedral.
|
||
|
||
**Parameters**
|
||
|
||
* **other** ([*CNOTDihedral*](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")) – a CNOTDihedral object.
|
||
* **qargs** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)") *or None*) – Optional, a list of subsystem positions to apply other on. If None apply on all subsystems (default: None).
|
||
* **front** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)")) – If True compose using right operator multiplication, instead of left multiplication \[default: False].
|
||
|
||
**Returns**
|
||
|
||
The composed CNOTDihedral.
|
||
|
||
**Return type**
|
||
|
||
[CNOTDihedral](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if other cannot be converted to an operator, or has incompatible dimensions for specified subsystems.
|
||
|
||
<Admonition title="Note" type="note">
|
||
Composition (`&`) by default is defined as left matrix multiplication for matrix operators, while `@` (equivalent to [`dot()`](#qiskit.quantum_info.CNOTDihedral.dot "qiskit.quantum_info.CNOTDihedral.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()`](#qiskit.quantum_info.CNOTDihedral.dot "qiskit.quantum_info.CNOTDihedral.dot") method `A.dot(B) == A.compose(B, front=True)`.
|
||
</Admonition>
|
||
</Function>
|
||
|
||
### conjugate
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.conjugate" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L447-L471" signature="conjugate()">
|
||
Return the conjugate of the CNOTDihedral.
|
||
</Function>
|
||
|
||
### copy
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.copy" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/base_operator.py#L143-L145" signature="copy()">
|
||
Make a deep copy of current operator.
|
||
</Function>
|
||
|
||
### dot
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.dot" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/mixins/group.py#L133-L149" signature="dot(other, qargs=None)">
|
||
Return the right multiplied operator self \* other.
|
||
|
||
**Parameters**
|
||
|
||
* **other** ([*Operator*](qiskit.quantum_info.Operator "qiskit.quantum_info.Operator")) – an operator object.
|
||
* **qargs** ([*list*](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.12)") *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**
|
||
|
||
[Operator](qiskit.quantum_info.Operator "qiskit.quantum_info.Operator")
|
||
|
||
<Admonition title="Note" type="note">
|
||
The dot product can be obtained using the `@` binary operator. Hence `a.dot(b)` is equivalent to `a @ b`.
|
||
</Admonition>
|
||
</Function>
|
||
|
||
### expand
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.expand" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L439-L440" signature="expand(other)">
|
||
Return the reverse-order tensor product with another CNOTDihedral.
|
||
|
||
**Parameters**
|
||
|
||
**other** ([*CNOTDihedral*](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.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**
|
||
|
||
[CNOTDihedral](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")
|
||
</Function>
|
||
|
||
### input\_dims
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.input_dims" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/base_operator.py#L135-L137" signature="input_dims(qargs=None)">
|
||
Return tuple of input dimension for specified subsystems.
|
||
</Function>
|
||
|
||
### output\_dims
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.output_dims" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/base_operator.py#L139-L141" signature="output_dims(qargs=None)">
|
||
Return tuple of output dimension for specified subsystems.
|
||
</Function>
|
||
|
||
### power
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.power" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/mixins/group.py#L151-L171" signature="power(n)">
|
||
Return the compose of a operator with itself n times.
|
||
|
||
**Parameters**
|
||
|
||
**n** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) – the number of times to compose with self (n>0).
|
||
|
||
**Returns**
|
||
|
||
the n-times composed operator.
|
||
|
||
**Return type**
|
||
|
||
[Clifford](qiskit.quantum_info.Clifford "qiskit.quantum_info.Clifford")
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if the input and output dimensions of the operator are not equal, or the power is not a positive integer.
|
||
</Function>
|
||
|
||
### reshape
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.reshape" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/base_operator.py#L106-L133" signature="reshape(input_dims=None, output_dims=None, num_qubits=None)">
|
||
Return a shallow copy with reshaped input and output subsystem dimensions.
|
||
|
||
**Parameters**
|
||
|
||
* **input\_dims** (*None or* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.12)")) – new subsystem input dimensions. If None the original input dims will be preserved \[Default: None].
|
||
* **output\_dims** (*None or* [*tuple*](https://docs.python.org/3/library/stdtypes.html#tuple "(in Python v3.12)")) – new subsystem output dimensions. If None the original output dims will be preserved \[Default: None].
|
||
* **num\_qubits** (*None or* [*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.12)")) – reshape to an N-qubit operator \[Default: None].
|
||
|
||
**Returns**
|
||
|
||
returns self with reshaped input and output dimensions.
|
||
|
||
**Return type**
|
||
|
||
BaseOperator
|
||
|
||
**Raises**
|
||
|
||
[**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") – if combined size of all subsystem input dimension or subsystem output dimensions is not constant.
|
||
</Function>
|
||
|
||
### tensor
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.tensor" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L436-L437" signature="tensor(other)">
|
||
Return the tensor product with another CNOTDihedral.
|
||
|
||
**Parameters**
|
||
|
||
**other** ([*CNOTDihedral*](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.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**
|
||
|
||
[CNOTDihedral](#qiskit.quantum_info.CNOTDihedral "qiskit.quantum_info.CNOTDihedral")
|
||
|
||
<Admonition title="Note" type="note">
|
||
The tensor product can be obtained using the `^` binary operator. Hence `a.tensor(b)` is equivalent to `a ^ b`.
|
||
</Admonition>
|
||
</Function>
|
||
|
||
### to\_circuit
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.to_circuit" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L317-L334" signature="to_circuit()">
|
||
Return a QuantumCircuit implementing the CNOT-Dihedral element.
|
||
|
||
**Returns**
|
||
|
||
a circuit implementation of the CNOTDihedral object.
|
||
|
||
**Return type**
|
||
|
||
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
|
||
|
||
**References**
|
||
|
||
1. Shelly Garion and Andrew W. Cross, *Synthesis of CNOT-Dihedral circuits with optimal number of two qubit gates*, [Quantum 4(369), 2020](https://quantum-journal.org/papers/q-2020-12-07-369/)
|
||
2. Andrew W. Cross, Easwar Magesan, Lev S. Bishop, John A. Smolin and Jay M. Gambetta, *Scalable randomized benchmarking of non-Clifford gates*, npj Quantum Inf 2, 16012 (2016).
|
||
</Function>
|
||
|
||
### to\_instruction
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.to_instruction" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L336-L338" signature="to_instruction()">
|
||
Return a Gate instruction implementing the CNOTDihedral object.
|
||
</Function>
|
||
|
||
### to\_matrix
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.to_matrix" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L366-L368" signature="to_matrix()">
|
||
Convert operator to Numpy matrix.
|
||
</Function>
|
||
|
||
### to\_operator
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.to_operator" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L370-L372" signature="to_operator()">
|
||
Convert to an Operator object.
|
||
|
||
**Return type**
|
||
|
||
[*Operator*](qiskit.quantum_info.Operator "qiskit.quantum_info.operators.operator.Operator")
|
||
</Function>
|
||
|
||
### transpose
|
||
|
||
<Function id="qiskit.quantum_info.CNOTDihedral.transpose" github="https://github.com/Qiskit/qiskit/tree/main/qiskit/quantum_info/operators/dihedral/dihedral.py#L473-L476" signature="transpose()">
|
||
Return the transpose of the CNOTDihedral.
|
||
</Function>
|
||
</Class>
|
||
|