Circuits API Reference
This page documents the classes and functions available in the skq.circuits
module. This module provides tools for creating and manipulating quantum circuits, as well as implementations of quantum algorithms.
Circuit Building Blocks
Circuit
skq.circuits.Circuit
Bases: list
Run multiple qubit gates in sequence.
Source code in src/skq/circuits/circuit.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
convert(framework='qiskit')
Convert circuit to a given framework. :param framework: Framework to convert to. :return: Converter Circuit object. For Qiskit -> QuantumCircuit object. For QASM -> OpenQASM string.
Source code in src/skq/circuits/circuit.py
30 31 32 33 34 35 36 37 38 39 |
|
draw(**kwargs)
Draw circuit using Qiskit.
Source code in src/skq/circuits/circuit.py
41 42 43 |
|
Concat
from skq.circuits import Circuit, Concat
from skq.gates import H, I
# Apply Hadamard to first qubit and Identity to second qubit
parallel_gates = Concat([H(), I()])
# Create a circuit with these parallel gates
circuit = Circuit([parallel_gates])
skq.circuits.Concat
Combine multiple qubit gates into a single gate. :param gates: List of gates to concatenate.
Source code in src/skq/circuits/circuit.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
decodes(x)
Reverse propagation for all gates.
:param x: Quantum state to decode. :return: Quantum state after decoding.
Source code in src/skq/circuits/circuit.py
68 69 70 71 72 73 74 75 76 77 |
|
encodes(x)
Concatenate 2 or more gates.
:param x: Quantum state to encode. :return: Quantum state after encoding.
Source code in src/skq/circuits/circuit.py
59 60 61 62 63 64 65 66 |
|
Quantum Algorithms
Bell States
The BellStates
class provides circuits for creating the four Bell states, which are maximally entangled two-qubit states.
from skq.circuits import BellStates
# Create a circuit for the Φ+ Bell state (|00⟩ + |11⟩)/√2
bell_circuit = BellStates().circuit(configuration=1)
# Create a circuit for the Ψ- Bell state (|01⟩ - |10⟩)/√2
bell_circuit = BellStates().circuit(configuration=4)
skq.circuits.BellStates
Convenience class for generating Bell States as skq Pipelines. More information on defining Bell States: - https://quantumcomputinguk.org/tutorials/introduction-to-bell-states - https://quantumcomputing.stackexchange.com/a/2260
Source code in src/skq/circuits/entangled_states.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
circuit(configuration=1)
Return circuit for the Bell State based on the configuration. :param configuration: Configuration of the Bell State. Configuration 1: |Φ+⟩ =|00> + |11> / sqrt(2) Configuration 2: |Φ-⟩ =|00> - |11> / sqrt(2) Configuration 3: |Ψ+⟩ =|01> + |10> / sqrt(2) Configuration 4: |Ψ-⟩ =|01> - |10> / sqrt(2) :return: Circuit for the Bell State.
Source code in src/skq/circuits/entangled_states.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
omega_minus()
Return circuit for the entangled state |Φ−⟩ =|00> - |11> / sqrt(2). This corresponds to the 2nd bell state. :return: Circuit for creating the 2nd Bell State
Source code in src/skq/circuits/entangled_states.py
44 45 46 47 48 49 50 51 |
|
omega_plus()
Return circuit for the entangled state |Φ+⟩ =|00> + |11> / sqrt(2). This corresponds to the 1st bell state. :return: Circuit for creating the 1st Bell State.
Source code in src/skq/circuits/entangled_states.py
36 37 38 39 40 41 42 |
|
phi_minus()
Return circuit for the entangled state |Ψ−⟩ =|01> - |10> / sqrt(2). This corresponds to the 4th bell state. :return: Circuit for creating the 4th Bell State
Source code in src/skq/circuits/entangled_states.py
61 62 63 64 65 66 67 |
|
phi_plus()
Return circuit for the entangled state |Ψ+⟩ =|01> + |10> / sqrt(2). This corresponds to the 3rd bell state. :return: Circuit for creating the 3rd Bell State
Source code in src/skq/circuits/entangled_states.py
53 54 55 56 57 58 59 |
|
GHZ States
The GHZStates
class provides circuits for creating Greenberger-Horne-Zeilinger (GHZ) states, which are multi-qubit generalizations of Bell states.
from skq.circuits import GHZStates
# Create a circuit for a 3-qubit GHZ state (|000⟩ + |111⟩)/√2
ghz_circuit = GHZStates().circuit(n_qubits=3)
skq.circuits.GHZStates
Generalization of Bell States to 3 or more qubits. Greenberger-Horne-Zeilinger (GHZ) states.
Source code in src/skq/circuits/entangled_states.py
70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
circuit(n_qubits)
:param n_qubits: Number of qubits in the GHZ state. :return: Circuit for the GHZ state.
Source code in src/skq/circuits/entangled_states.py
76 77 78 79 80 81 82 |
|
W State
The WState
class provides a circuit for creating the 3-qubit W state, which is another type of entangled state.
from skq.circuits import WState
# Create a circuit for the W state (|001⟩ + |010⟩ + |100⟩)/√3
w_circuit = WState().circuit()
skq.circuits.WState
3-qubit W State: (|001⟩ + |010⟩ + |100⟩)/√3
Source code in src/skq/circuits/entangled_states.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
Deutsch's Algorithm
The Deutsch
class implements Deutsch's algorithm, which determines whether a function is constant or balanced with a single query.
from skq.circuits import Deutsch
# Define a constant function (always returns 0)
def constant_function(x):
return 0
# Create a circuit for Deutsch's algorithm
deutsch_circuit = Deutsch().circuit(f=constant_function)
skq.circuits.Deutsch
Deutsch's algorithm.
Source code in src/skq/circuits/deutsch.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
circuit(f, measure=True)
Deutsch's algorithm :param f: Binary function that maps a single bit to a single bit. :param measure: Whether to measure the qubits. :return: skq Circuit that implements Deutsch's algorithm.
Source code in src/skq/circuits/deutsch.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Deutsch-Jozsa Algorithm
The DeutschJozsa
class implements the Deutsch-Jozsa algorithm, which is a generalization of Deutsch's algorithm to multiple qubits.
from skq.circuits import DeutschJozsa
# Define a constant function for multiple bits
def constant_function(x):
return 0
# Create a circuit for the Deutsch-Jozsa algorithm with 3 qubits
dj_circuit = DeutschJozsa().circuit(f=constant_function, n_bits=3)
skq.circuits.DeutschJozsa
Deutsch-Jozsa algorithm.
Source code in src/skq/circuits/deutsch.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
circuit(f, n_bits, measure=True)
Deutsch-Josza algorithm :param f: Binary function that maps a single bit to a single bit. :return: skq Circuit that implements Deutsch-Josza algorithm.
Source code in src/skq/circuits/deutsch.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
Grover's Algorithm
The Grover
class implements Grover's search algorithm, which can find a marked item in an unsorted database quadratically faster than classical algorithms.
from skq.circuits import Grover
import numpy as np
# Create a target state to search for (|100⟩)
target_state = np.zeros(8)
target_state[4] = 1
# Create a circuit for Grover's algorithm
grover_circuit = Grover().circuit(
target_state=target_state,
n_qubits=3,
n_iterations=1
)
skq.circuits.Grover
Grover's search algorithm.
Source code in src/skq/circuits/grover.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
circuit(target_state, n_qubits, n_iterations, measure=True)
Grover's search algorithm :param target_state: Target state to search for. :param n_qubits: Number of qubits in the circuit. :param n_iterations: Number of Grover iterations to perform. :param measure: Whether to measure the qubits. :return: Circuit for the Grover search algorithm.
Source code in src/skq/circuits/grover.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
Circuit Conversion
SKQ circuits can be converted to other quantum computing frameworks:
from skq.circuits import Circuit, Concat
from skq.gates import H, I, CX
# Create a Bell state circuit
bell_circuit = Circuit([
Concat([H(), I()]), # Apply H to first qubit, I to second qubit
CX() # Apply CNOT with first qubit as control
])
# Convert to Qiskit
qiskit_circuit = bell_circuit.convert(framework="qiskit")
# Convert to OpenQASM
qasm_code = bell_circuit.convert(framework="qasm")
skq.circuits.convert_to_qiskit(circuit)
Convert a skq Circuit into a Qiskit QuantumCircuit.
Source code in src/skq/circuits/circuit.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
skq.circuits.convert_to_qasm(circuit)
Convert a skq Circuit into an OpenQASM string.
Source code in src/skq/circuits/circuit.py
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|