Quantum Gates on Dynex - dynexcoin/DynexSDK GitHub Wiki
Quantum gates are the fundamental building blocks of quantum circuits, analogous to classical logic gates in traditional computing. They manipulate the state of qubits, the quantum analogs of classical bits, by performing specific quantum operations. Unlike classical gates, quantum gates can create and manage superposition, entanglement, and other quantum phenomena, enabling quantum computers to solve problems that are intractable for classical computers. Each gate operates on one or more qubits, altering their probability amplitudes and phases to evolve the quantum state according to the principles of quantum mechanics.
The following quantum gates are supported by the Dynex SDK:
Pauli-X and RX Gate
The Pauli-X gate (also known as the NOT gate) flips the qubit state. This means X|0⟩ = |1⟩ and X|1⟩ = |0⟩.
Here’s how the Pauli-X and RX gates are represented in PennyLane, OpenQASM, and Qiskit:
Pauli-X Gate:
- PennyLane:
qml.PauliX(wires=0)
- OpenQASM:
x q[0];
- Qiskit:
qc.x(0)
RX Gate:
- PennyLane:
qml.RX(angle, wires=0)
- OpenQASM:
rx(angle) q[0];
- Qiskit:
qc.rx(angle, 0)
In each of these frameworks, these commands apply the corresponding gate to the qubit indexed at position 0.
Pauli-Y and RY Gate
The Pauli-Y gate introduces a phase flip and then a bit flip. This means Y |0⟩ = i|1⟩ and Y |1⟩ = −i|0⟩.
Here’s how the Pauli-Y and RY gates are represented in PennyLane, OpenQASM, and Qiskit:
Pauli-Y Gate:
- PennyLane:
qml.PauliY(wires=0)
- OpenQASM:
y q[0];
- Qiskit:
qc.y(0)
RY Gate:
- PennyLane:
qml.RY(angle, wires=0)
- OpenQASM:
ry(angle) q[0];
- Qiskit:
qc.ry(angle, 0)
In each of these frameworks, these commands apply the corresponding gate to the qubit indexed at position 0. The angle in the RY gate represents the rotation angle around the Y-axis.
Pauli-Z and RZ Gate
The Pauli-Z gate flips the phase of the qubit. This means Z|0⟩ = |0⟩ and Z|1⟩ = −|1⟩.
Here’s how the Pauli-Z and RZ gates are represented in PennyLane, OpenQASM, and Qiskit:
Pauli-Z Gate:
- PennyLane:
qml.PauliZ(wires=0)
- OpenQASM:
z q[0];
- Qiskit:
qc.z(0)
RZ Gate:
- PennyLane:
qml.RZ(angle, wires=0)
- OpenQASM:
rz(angle) q[0];
- Qiskit:
qc.rz(angle, 0)
In each of these frameworks, these commands apply the corresponding gate to the qubit indexed at position 0. The angle in the RZ gate represents the rotation angle around the Z-axis.
Controlled-NOT (CNOT) Gate
The CNOT gate negates the target qubit if and only if the control qubit is 1.
The truth table for the CNOT gate is:
Control | Target | Control (out) | Target (out) |
---|---|---|---|
0 | 0 | 0 | 0 |
0 | 1 | 0 | 1 |
1 | 0 | 1 | 1 |
1 | 1 | 1 | 0 |
Here’s how the Controlled-NOT (CNOT) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled-NOT (CNOT) Gate:
- PennyLane:
qml.CNOT(wires=[0, 1])
- OpenQASM:
cx q[0], q[1];
- Qiskit:
qc.cx(0, 1)
In each of these frameworks, the CNOT gate applies a NOT operation to the target qubit (qubit 1 in this case) if the control qubit (qubit 0) is in the |1⟩ state. The qubits are specified by their indices in the quantum register.
Toffoli Gate
The Toffoli gate (also known as the CCNOT gate) flips the third bit if and only if the first two bits are both 1.
The truth table for the Toffoli gate is:
Control 1 | Control 2 | Target | Control 1 (out) | Control 2 (out) | Target (out) |
---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 1 | 0 |
0 | 1 | 1 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 0 |
1 | 0 | 1 | 1 | 0 | 1 |
1 | 1 | 0 | 1 | 1 | 1 |
1 | 1 | 1 | 1 | 1 | 0 |
Here’s how the Toffoli gate (also known as the CCNOT or Controlled-Controlled-NOT gate) is represented in PennyLane, OpenQASM, and Qiskit:
Toffoli (CCNOT) Gate:
- PennyLane:
qml.Toffoli(wires=[0, 1, 2])
- OpenQASM:
ccx q[0], q[1], q[2];
- Qiskit:
qc.ccx(0, 1, 2)
In each of these frameworks, the Toffoli gate flips the state of the target qubit (qubit 2) if both control qubits (qubits 0 and 1) are in the |1⟩ state. The qubits are specified by their indices in the quantum register.
Fredkin (SWAP) Gate
The Fredkin gate swaps the last two bits if and only if the first bit is 1.
The truth table for the Fredkin gate is:
Control | Target 1 | Target 2 | Control (out) | Target 1 (out) | Target 2 (out) |
---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 |
0 | 0 | 1 | 0 | 0 | 1 |
0 | 1 | 0 | 0 | 1 | 0 |
0 | 1 | 1 | 0 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 0 |
1 | 0 | 1 | 1 | 1 | 0 |
1 | 1 | 0 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 1 | 1 |
Here’s how the Fredkin (SWAP) gate is represented in PennyLane, OpenQASM, and Qiskit:
Fredkin (SWAP) Gate:
- PennyLane:
qml.SWAP(wires=[1, 2])
- OpenQASM:
swap q[1], q[2];
- Qiskit:
qc.swap(1, 2)
In each of these frameworks, the SWAP gate exchanges the quantum states of the two specified qubits. In this example, the states of qubits 1 and 2 are swapped. The qubits are specified by their indices in the quantum register.
Hadamard (H) Gate
The Hadamard gate creates a superposition of basis states.
Here’s how the Hadamard (H) gate is represented in PennyLane, OpenQASM, and Qiskit:
Hadamard (H) Gate:
- PennyLane:
qml.Hadamard(wires=0)
- OpenQASM:
h q[0];
- Qiskit:
qc.h(0)
In each of these frameworks, the Hadamard gate is applied to the specified qubit (qubit 0 in this example), placing it in an equal superposition of the |0⟩ and |1⟩ states. The qubits are specified by their indices in the quantum register.
Controlled-Z (CZ) Gate
The CZ gate applies a Pauli-Z operation to the target qubit if the control qubit is in the state —1.
Here’s how the Controlled-Z (CZ) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled-Z (CZ) Gate:
- PennyLane:
qml.CZ(wires=[0, 1])
- OpenQASM:
cz q[0], q[1];
- Qiskit:
qc.cz(0, 1)
In each of these frameworks, the CZ gate applies a Z gate (phase flip) to the target qubit (qubit 1) if the control qubit (qubit 0) is in the |1⟩ state. The qubits are specified by their indices in the quantum register.
Controlled-Rotation-X (CRX) Gate
The CRX gate applies a rotation around the X-axis to the target qubit if the control qubit is —1.
Here’s how the Controlled-Rotation-X (CRX) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled-Rotation-X (CRX) Gate:
- PennyLane:
qml.CRX(angle, wires=[0, 1])
- OpenQASM:
crx(angle) q[0], q[1];
- Qiskit:
qc.crx(angle, 0, 1)
In each of these frameworks, the CRX gate applies an RX rotation to the target qubit (qubit 1) by the specified angle, only if the control qubit (qubit 0) is in the |1⟩ state. The qubits are specified by their indices in the quantum register.
Controlled-Rotation-Y (CRY) Gate
The CRY gate applies a rotation around the Y-axis to the target qubit if the control qubit is —1.
Here’s how the Controlled-Rotation-Y (CRY) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled-Rotation-Y (CRY) Gate:
- PennyLane:
qml.CRY(angle, wires=[0, 1])
- OpenQASM:
cry(angle) q[0], q[1];
- Qiskit:
qc.cry(angle, 0, 1)
In each of these frameworks, the CRY gate applies a rotation around the Y-axis to the target qubit (qubit 1) by the specified angle, only if the control qubit (qubit 0) is in the |1⟩ state. The qubits are specified by their indices in the quantum register.
Controlled-Rotation-Z (CRZ) Gate
The CRZ gate applies a rotation around the Z-axis to the target qubit if the control qubit is —1.
Here’s how the Controlled-Rotation-Z (CRZ) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled-Rotation-Z (CRZ) Gate:
- PennyLane:
qml.CRZ(angle, wires=[0, 1])
- OpenQASM:
crz(angle) q[0], q[1];
- Qiskit:
qc.crz(angle, 0, 1)
In each of these frameworks, the CRZ gate applies a rotation around the Z-axis to the target qubit (qubit 1) by the specified angle, only if the control qubit (qubit 0) is in the |1⟩ state. The qubits are specified by their indices in the quantum register.
T Gate
The T gate applies a phase shift of π/4 (or 45 degrees).
Here’s how the T gate is represented in PennyLane, OpenQASM, and Qiskit:
T Gate:
- PennyLane:
qml.T(wires=0)
- OpenQASM:
t q[0];
- Qiskit:
qc.t(0)
In each of these frameworks, the T gate is applied to the specified qubit (qubit 0 in this example). The T gate is a non-Clifford gate that applies a π/4 phase shift to the qubit, playing an essential role in quantum circuits for enabling more complex quantum computations.
Basis Embedding Gate
A general basis transformation can be represented by a unitary matrix U. For example, let’s consider the transformation to the Fourier basis. The discrete Fourier transform (DFT) matrix for a single qubit is the Hadamard matrix H.
The concept of a "Basis Embedding" gate is typically used to encode classical data into a quantum state, where the binary representation of a number is mapped directly onto the computational basis states of the qubits.
Basis Embedding:
- PennyLane:
qml.BasisEmbedding(features, wires=[0, 1, 2])
- OpenQASM: There isn't a direct equivalent in OpenQASM for Basis Embedding, as it's more of a high-level concept implemented in specific frameworks like PennyLane.
- Qiskit: Qiskit typically uses more manual methods for basis embedding, like applying X gates conditionally.
In PennyLane, qml.BasisEmbedding(features, wires=[0, 1, 2])
encodes the binary representation of the input data directly onto the qubits.
Controlled Phase Shift Gate
A Controlled Phase Shift gate CRk applies a phase shift Rk to the target qubit if the control qubit is in the state |1⟩. This can be generalized to CR(φ) for any phase shift φ. This means the target qubit acquires a phase φ only if the control qubit is |1⟩.
Here’s how the Controlled Phase Shift gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled Phase Shift Gate:
- PennyLane:
qml.ControlledPhaseShift(angle, wires=[0, 1])
- OpenQASM: OpenQASM does not have a direct command for a controlled phase shift, but you can implement it using custom gate definitions.
- Qiskit:
qc.cp(angle, 0, 1)
In these frameworks, the Controlled Phase Shift gate applies a phase shift of the specified angle to the target qubit (qubit 1) when the control qubit (qubit 0) is in the |1⟩ state.
Controlled Qubit Unitary (CU) Gate
For a controlled unitary gate CU with control qubit qj and target qubit qi, the operation can be represented as: CU = (I 0 / 0 U) where I is the identity matrix applied when the control qubit is |0⟩, and U is the unitary operation applied when the control qubit is |1⟩.
Here’s how the Controlled Unitary (CU) gate is represented in PennyLane, OpenQASM, and Qiskit:
Controlled Unitary (CU) Gate:
- PennyLane:
qml.ControlledQubitUnitary(U, control_wires=[0], wires=[1])
- OpenQASM: OpenQASM does not have a direct command for a general controlled unitary, but you can implement it using custom gate definitions.
- Qiskit:
qc.append(qiskit.circuit.library.CU(angle, 0, 0, 0), [0, 1])
(or custom gate with control)
In these frameworks, the CU gate applies a unitary operation 𝑈 to the target qubit (qubit 1) when the control qubit (qubit 0) is in the |1⟩ state. The unitary 𝑈 can be any 2x2 matrix.
Quantum Fourier Transform (QFT)
For an n-qubit system, the QFT can be decomposed into a series of Hadamard gates and controlled phase shift gates. Specifically, for a 2-qubit QFT, it involves the following steps:
- Apply a Hadamard gate to the first qubit.
- Apply a controlled phase shift Rk to the first qubit controlled by the second qubit.
- Swap the qubits.
- Apply a Hadamard gate to the second qubit.
- Apply a controlled phase shift Rk−1 to the second qubit controlled by the first qubit.
Here’s how the Quantum Fourier Transform (QFT) is represented in PennyLane, OpenQASM, and Qiskit:
Quantum Fourier Transform (QFT):
- PennyLane: PennyLane does not have a built-in QFT gate, but it can be implemented using a series of Hadamard and controlled rotation gates:
def qft(wires):
qml.QFT(wires=wires)
- OpenQASM: OpenQASM does not have a built-in QFT command, but it can be implemented manually using a sequence of gates.
- Qiskit:
qc.append(qiskit.circuit.library.QFT(num_qubits).decompose(), range(num_qubits))
In these frameworks, the QFT transforms the quantum state into the Fourier basis, which is a critical operation in many quantum algorithms.
The Adjoint (Dagger)
The adjoint of a gate U is denoted U† and its matrix elements are the complex conjugates of the transposed elements of U. When translating these into the AQC framework, we follow the same procedure as for the original gates but apply the complex conjugation.
Here’s how the Adjoint (or Dagger) operation is represented in PennyLane, OpenQASM, and Qiskit:
Adjoint (Dagger):
- PennyLane: Use the
qml.adjoint()
context to reverse the effect of a quantum operation.
with qml.adjoint(qml.Hadamard)(wires=0):
# Apply the adjoint (dagger) of the Hadamard gate
- OpenQASM: OpenQASM does not have a direct command for adjoint, but you can manually reverse the operation sequence.
- Qiskit: Use the
.inverse()
method on a gate or circuit.
qc.h(0).inverse()
In these frameworks, the adjoint or dagger operation applies the Hermitian conjugate (inverse) of a given quantum gate or operation.
Next: Dynex Circuit Class