skq
Scientific Toolkit for Quantum Computing
This library is used in the q4p (Quantum Computing for Programmers) course.
NOTE: This library is developed for educational purposes. While we strive for correctness of everything, the code is provided as is and not guaranteed to be bug-free. For sensitive applications make sure you check computations.
Why SKQ?
- Exploration: Play with fundamental quantum building blocks using NumPy.
- Education: Learn quantum computing concepts and algorithms.
- Integration: Combine classical components with quantum components.
- Democratize quantum for Python programmers and data scientists: Develop quantum algorithms in your favorite environment and easily export to your favorite quantum computing platform for running on real quantum hardware.
Install
pip install -U skq
Quickstart
Circuit Conversion
Run this code snippet to initialize Grover's algorithm and convert to Qiskit to run on quantum hardware. The algorithm can also be run within skq as a classical simulation.
from skq.circuits import Grover
# Initialize Grover's search skq Circuit
circuit = Grover().circuit(n_qubits=3, target_state=np.array([0, 0, 0, 0, 1, 0, 0, 0]), n_iterations=1)
# Conversion to Qiskit
qiskit_circuit = circuit.convert(framework="qiskit")
qiskit_circuit.draw()
# ┌───┐┌──────────────┐┌──────────────────┐┌─┐
# q_0: ┤ H ├┤0 ├┤0 ├┤M├──────
# ├───┤│ ││ │└╥┘┌─┐
# q_1: ┤ H ├┤1 PhaseOracle ├┤1 GroverDiffusion ├─╫─┤M├───
# ├───┤│ ││ │ ║ └╥┘┌─┐
# q_2: ┤ H ├┤2 ├┤2 ├─╫──╫─┤M├
# └───┘└──────────────┘└──────────────────┘ ║ ║ └╥┘
# c: 3/══════════════════════════════════════════╩══╩══╩═
# 0 1 2
# Run circuit as classical simulation
print(grover([1,0,0,0,0,0,0,0]))
# array([0.03125, 0.03125, 0.03125, 0.03125, 0.78125, 0.03125, 0.03125, 0.03125])
Circuits from scratch
You can also build your own custom circuits from scratch using individual gates. All gates can be converted to popular frameworks like Qiskit and OpenQASM.
from skq.gates import H, I, CX
from skq.circuits import Concat, Circuit
H() # Hadamard gate (NumPy array)
# H([[ 0.70710678+0.j, 0.70710678+0.j],
# [ 0.70710678+0.j, -0.70710678+0.j]])
I() # Identity gate (NumPy array)
# I([[1.+0.j, 0.+0.j],
# [0.+0.j, 1.+0.j]])
CX() # CNOT gate (NumPy array)
# CX([[1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j],
# [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j],
# [0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j],
# [0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j]])
# Initialize Bell State skq Circuit
circuit = Circuit([Concat([H(), I()]), CX()])
# Simulate circuit classically
state = np.array([1, 0, 0, 0]) # |00> state
circuit(state)
# array([0.70710678+0.j, 0, 0, 0.70710678+0.j])
# Conversion to Qiskit (Identity gates are removed)
qiskit_circuit = circuit.convert(framework="qiskit")
qiskit_circuit.draw()
# ┌───┐
# q_0: ┤ H ├──■──
# └───┘┌─┴─┐
# q_1: ─────┤ X ├
# └───┘
# Conversion to OpenQASM
qasm_circuit = circuit.convert(framework="qasm")
print(qasm_circuit)
# h q[0];
# cx q[0], q[1];
Metadata
Release files for skq 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| skq-0.4.6.tar.gz | 38.4 kB | Without provenance | Details for skq-0.4.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| skq-0.4.6-py3-none-any.whl | Python 3 | none | any | Details for skq-0.4.6-py3-none-any.whl |
Total release size: 81.1 kB
Release files / skq-0.4.6.tar.gz
| Download URL | skq-0.4.6.tar.gz |
|---|---|
| Size | 38.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1b9adb42f2a9d5e8190e396ede01c7bc69104a46081565ea99814138efc4f50a
|
|
BLAKE2b-256 checksum How to use checksums |
ab94aa0f3b75ad03f9dde029bb196d15e9fb58d977ff9f238b85da64ecf50d7a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.12
|
Release files / skq-0.4.6-py3-none-any.whl
| Download URL | skq-0.4.6-py3-none-any.whl |
|---|---|
| Size | 42.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8a9758bf626f22b0a56fa0ba59fe8a93a873cc3321937ed3e03de02f1bd0369
|
|
BLAKE2b-256 checksum How to use checksums |
bf1da40b6bf4465a3f8a3d50d32b14b03cd199c8dbda009afbbc2e3b61cd037e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.12
|
Security for skq 0.4.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.