Skip to main content

Scientific Toolkit for Quantum Computing

Project description

skq

Python Version uv Ruff

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];

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

skq-0.4.5.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

skq-0.4.5-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

Details for the file skq-0.4.5.tar.gz.

File metadata

  • Download URL: skq-0.4.5.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.12

File hashes

Hashes for skq-0.4.5.tar.gz
Algorithm Hash digest
SHA256 1f5024c5b51489deef867bb4cf819778b62a02ddbe9d092b56f42f069a115b94
MD5 badefbe7ba5d08e776fb1c9134042d36
BLAKE2b-256 e6c9a6966642681869bdc1e464068efed43b69308771fcc77904c79a943e960c

See more details on using hashes here.

File details

Details for the file skq-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: skq-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 42.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.12

File hashes

Hashes for skq-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 78aaf2375a6879013d9328075a2a6e16bda5c287a6e6faa32eff1f16e3044f1e
MD5 508fbe072f4eed8e840dd8bcd0d8bb64
BLAKE2b-256 fa615305e62628a35b2b551a34d5d588125e4be2bbf6d70eb67b7951166f3284

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page