Quantum Gates ----------------- What are Quantum Gates? -------------------------- In quantum computing, quantum gates are the fundamental operations that manipulate the state of qubits. They are analogous to classical logic gates (like AND, OR, NOT) in classical computing. However, they have unique properties that enable quantum computers to perform certain tasks more efficiently than classical computers. Key Properties of Quantum Gates --------------------------------- Reversible: Unlike some classical gates, quantum gates are inherently reversible. This means that the original state of the qubits can be recovered from the output state. Unitary: Quantum gates are represented by unitary matrices, which ensure that the system’s total probability remains conserved. Superposition and Entanglement: Quantum gates can create and manipulate quantum phenomena like superposition (qubits existing in multiple states simultaneously) and entanglement (correlations between qubits). Common Types of Quantum Gates -------------------------------- **Single-Qubit Gates** These gates operate on a single qubit, modifying its state in various ways. .. code-block:: python qc.add_gate(h, q[1]) qc.add_gate(rx(np.pi/2), q[2]) **Controlled Gates** .. code-block:: python qc.add_gate(cx, q[0], q[1]) qc.add_gate(ccx, q[0], q[1], q[2]) **Parameterized Gates** .. code-block:: python qc.add_gate(u3(np.pi/2, 0, 0), q[0]) List Available Gates ---------------------- .. code-block:: python qc=QniverseCircuit() qc.list_gates() Gates -------- id ~~~~~ Single qubit identity gate Qubits: 1 Example: .. code-block:: python qc.add_gate(id, q[3]) x ~~~~~ Pauli X (PI rotation over X-axis) aka "NOT" gate Qubits: 1 Example: .. code-block:: python qc.add_gate(x, q[2]) y ~~~~ Pauli Y (PI rotation over Y-axis) Qubits: 1 Example: .. code-block:: python qc.add_gate(y, q[1]) z ~~~~ Pauli Z (PI rotation over Z-axis) Qubits: 1 Example: .. code-block:: python qc.add_gate(z, q[2]) h ~~~~ Hadamard gate Qubits: 1 Example: .. code-block:: python qc.add_gate(h, q[1]) rx ~~~~ Rotation around the X-axis by given angle Qubits: 1 Parameters: theta Example: .. code-block:: python qc.add_gate(rx(np.pi/2), q[1]) ry ~~~~ Rotation around the Y-axis by given angle Qubits: 1 Parameters: theta Example: .. code-block:: python qc.add_gate(ry(np.pi/2), q[1]) rz ~~~~ Rotation around the Z-axis by given angle Qubits: 1 Parameters: phi Example: .. code-block:: python qc.add_gate(rz(np.pi/2), q[1]) u1 ~~~~ Single-qubit rotation about the Z axis Qubits: 1 Parameters: lambda Example: .. code-block:: python qc.add_gate(u1(np.pi/4),q[2]) u2 ~~~~ Single-qubit rotation about the X+Z axis Qubits: 1 Parameters: phi, lambda Example: .. code-block:: python qc.add_gate(u2(np.pi/2,0),q[2]) u3 ~~~~~ Generic single-qubit rotation gate with 3 Euler angles Qubits: 1 Parameters: theta, phi, lambda Example: .. code-block:: python qc.add_gate(u3(np.pi/2,0,0),q[2]) s ~~~ PI/2 rotation over Z-axis (synonym for r2) Qubits: 1 Example: .. code-block:: python qc.add_gate(s, q[2]) t ~~~ PI/4 rotation over Z-axis (synonym for r4) Qubits: 1 Example: .. code-block:: python qc.add_gate(t, q[2]) sdg ~~~~~~ (-PI/2) rotation over Z-axis Qubits: 1 Example: .. code-block:: python qc.add_gate(sdg, q[2]) tdg ~~~~~ (-PI/4) rotation over Z-axis Qubits: 1 Example: .. code-block:: python qc.add_gate(tdg, q[2]) cx ~~~~~ Controlled NOT (CNOT) gate Qubits: 2 Example: .. code-block:: python qc.add_gate(cx, q[2],q[4]) Or qc.add_gate(cnot, q[1],q[4]) ccx ~~~~~ Toffoli aka "CCNOT" gate Qubits: 3 Example: .. code-block:: python qc.add_gate(ccx, q[0],q[1],q[2]) c3x ~~~~~~ Qubits: 4 Example: .. code-block:: python qc.add_gate(c3x, q[0],q[1],q[2],q[3]) c4x ~~~~~ Qubits: 5 Example: .. code-block:: python qc.add_gate(c4x, q[0],q[1],q[2],q[3],q[4]) c5x ~~~~~ Qubits: 6 Example: .. code-block:: python qc.add_gate(c4x, q[0],q[1],q[2],q[3],q[4],q[5]) cy ~~~~ Controlled Y gate (controlled rotation over Y-axis by PI) Qubits: 2 Example: .. code-block:: python qc.add_gate(cy, q[1],q[2]) cz ~~~~~ Controlled Z gate (controlled rotation over Z-axis by PI) Qubits: 2 Example: .. code-block:: python qc.add_gate(cz, q[0],q[1]) ch ~~~~~ Controlled Hadamard gate Qubits: 2 Example: .. code-block:: python qc.add_gate(ch, q[0],q[1]) swap ~~~~~~ Swaps the state of two qubits. Qubits: 2 Example: .. code-block:: python qc.add_gate(swap, q[1],q[2]) crx ~~~~~~ Controlled rotation around the X-axis by given angle Qubits: 2 Parameters: theta Example: .. code-block:: python qc.add_gate(crx(np.pi/2), q[1],q[2]) cry ~~~~~~ Controlled rotation around the Y-axis by given angle Qubits: 2 Parameters: theta Example: .. code-block:: python qc.add_gate(cry(np.pi/2), q[1],q[2]) crz ~~~~~~ Controlled rotation around the Z-axis by given angle Qubits: 2 Parameters: phi Example: .. code-block:: python qc.add_gate(crz(np.pi/2), q[1],q[2]) cu1 ~~~~~~ Controlled rotation about the Z axis Qubits: 2 Parameters: Lambda Example: .. code-block:: python qc.add_gate(cu1(np.pi/2),q[2],q[3]) cu2 ~~~~~ Controlled rotation about the X+Z axis Qubits: 2 Parameters: phi, lambda Example: .. code-block:: python qc.add_gate(cu2(np.pi/2,0),q[2],q[3]) cu3 ~~~~~ Controlled rotation gate with 3 Euler angles Qubits: 2 Parameters: theta, phi, lambda Example: .. code-block:: python qc.add_gate(cu3(np.pi/2,0,0),q[2],q[3]) cs ~~~~ Controlled PI/2 rotation over Z-axis. Qubits: 2 Example: .. code-block:: python qc.add_gate(cs, q[0], q[1]) ct ~~~~~ Controlled PI/4 rotation over Z-axis. Qubits: 2 Example: .. code-block:: python qc.add_gate(ct, q[0], q[1]) csdg ~~~~~~ Controlled (-PI/2) rotation over Z-axis Qubits: 2 Example: .. code-block:: python qc.add_gate(csdg, q[0], q[1]) ctdg ~~~~~~ Controlled (-PI/4) rotation over Z-axis Qubits: 2 Example: .. code-block:: python qc.add_gate(ctdg, q[3], q[1]) cswap ~~~~~~~ Controlled swap aka "Fredkin" gate Qubits: 3 Example: .. code-block:: python qc.add_gate(cswap, q[1],q[2],q[3]) reset ~~~~~~~ Resets qubit Qubits: 1 Example: .. code-block:: python qc.add_gate(reset, q[0]) measure ~~~~~~~~~ Measures qubit and stores outcome (0 or 1) into classical register Qubits: 1 classical bits: 1 Example: .. code-block:: python qc.add_gate(measure, q[1], c[1]) Barrier ~~~~~~~~~ Qubits: 1 Example: .. code-block:: python qc.add_gate(barrier, q[0]) cp ~~~~~ Qubits: 2 Parameters: theta Example: .. code-block:: python qc.add_gate(cp(np.pi/2), q[0], q[1]) p ~~~~ Qubits: 1 Parameters: theta Example: .. code-block:: python qc.add_gate(p(np.pi/2), q[1]) Modules ------------ Modules represent a simple abstraction for multi-qubit quantum operations, such as the Quantum Fourier Transform (QFT) and its inverse (IQFT). It provides a flexible Module class for naming and grouping parameterized gates, also two predefined instances, qft and iqft, for ease of use across the library. Use ``add_module`` to apply composite circuits. .. code-block:: python from Qniverse.module import * qc.add_module(qft, q[1], q[2], q[3]) qc.add_module(iqft, q[1], q[3]) -------