Skip to main content

A visualisation tool for quantum information

Project description

CubeIt

CubeIt is a lightweight quantum playground for n-qubit registers. Universal gate set and utilities for visualisation and testing.

Features

  • N-Qubit Registers: Create registers of any size with quantumregister(n).
  • Universal Gate Set: L (h(), s(), t(), cnot(), …) (qr.h(i), qr.cnot(control, target)).
  • Measurement: get_state() prints amplitudes, measure() collapses and returns classical outcomes.
  • Utility Modules: Measurement statistics, Bell-state builders, fidelity checks, and more under cubeit.visualization.

Installation

pip install -r requirements.txt

Or install as a package:

pip install -e .

Quick Start

from cubeit import quantumregister, get_state, measure

# 1) Create a 4-qubit register (|0000⟩)
qr = quantumregister(4)

# 2) Build a circuit with fluent helpers
qr.h(0)          # Hadamard on qubit 0
qr.cnot(0, 1)    # Entangle qubit 0 and 1
qr.rx(2, 0.5)    # Rotate qubit 2 around X by 0.5 radians
qr.cz(1, 3)      # Controlled-Z between qubit 1 and 3

# 3) Inspect the statevector (pretty printed)
get_state(qr)

# 4) Measure – collapses the state and returns a bitstring
result = measure(qr)
print("Measurement:", result)

Gate Helpers at a Glance

Helper Description
qr.h(i) Hadamard on qubit i
qr.x(i), qr.y(i), qr.z(i) Pauli gates
qr.s(i), qr.t(i) Phase / π/8 gates
qr.rx(i, θ), qr.ry(i, θ), qr.rz(i, θ) Rotations
qr.cnot(control, target) Controlled-NOT
qr.cz(control, target) Controlled-Z
qr.cphase(control, target, φ) Controlled-phase
qr.swap(a, b) Swap two qubits

Prefer something functional? Import directly:

from cubeit import h, cnot, quantumregister

qr = quantumregister(2)
qr.apply_single_qubit_gate(h(), 0)
qr.apply_two_qubit_gate(cnot(), 0, 1)

Measurement & Probabilities

from cubeit import quantumregister, get_state, measure
from cubeit.visualization import print_probabilities

qr = quantumregister(2).h(0).cnot(0, 1)

print_probabilities(qr)
# Measurement Probabilities:
#   |00⟩: 0.5000 (50.00%)
#   |11⟩: 0.5000 (50.00%)

measure(qr)  # collapses the register and prints the classical outcome

Bell States & Visualisation

from cubeit.visualization import create_bell_state, print_state, print_measurement_stats

bell = create_bell_state("phi_plus")
print_state(bell)                 # 0.707|00⟩ + 0.707|11⟩
print_measurement_stats(bell)     # Monte-Carlo sampling

quantumregister

Factory returning an instance of the internal _QuantumRegister. Methods:

  • apply_gate(matrix) / apply_single_qubit_gate(matrix, qubit)
  • measure() & measure_qubit(qubit)
  • get_state() → returns a QuantumState
  • get_probabilities()np.ndarray
  • Fluent helpers: h, x, y, z, s, t, phase, rx, ry, rz, cnot, cz, cphase, swap

Gate Factories

Import functions directly from cubeit when you need raw matrices:

from cubeit import h, x, cnot, swap

u = h()          # 2x2 Hadamard matrix
cx = cnot()      # 4x4 CNOT (control=0, target=1)
swap_gate = swap()

Examples

Example 1: Creating a Bell State

from cubeit import quantumregister

qr = quantumregister(2)
qr.h(0).cnot(0, 1)
print(qr)
# QuantumRegister(2 qubits):
#   0.707|00⟩ + 0.707|11⟩

Example 2: Measurement Statistics

from cubeit import quantumregister
from cubeit.visualization import print_measurement_stats

qr = quantumregister(2).h(0).cnot(0, 1)

print_measurement_stats(qr, num_samples=1000)

Theory

Universal Gate Set

The set {h, s, t, CNOT} form a universal gate set. Any unitary operation can be approximated to arbitrary precision using these primitives.

  • H: Creates superposition states
  • S: Applies π/2 phase rotation
  • T: Applies π/4 phase rotation
  • CNOT: Creates entanglement between qubits

Two-Qubit States

A two-qubit system has a 4-dimensional state space with basis states:

  • |00⟩ = [1, 0, 0, 0]ᵀ
  • |01⟩ = [0, 1, 0, 0]ᵀ
  • |10⟩ = [0, 0, 1, 0]ᵀ
  • |11⟩ = [0, 0, 0, 1]ᵀ

Any two-qubit state can be written as: |ψ⟩ = α|00⟩ + β|01⟩ + γ|10⟩ + δ|11⟩

where |α|² + |β|² + |γ|² + |δ|² = 1.

Requirements

  • Python >= 3.8
  • NumPy >= 1.20.0

License

See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

cubeit-0.0.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

cubeit-0.0.1-py3-none-any.whl (31.3 kB view details)

Uploaded Python 3

File details

Details for the file cubeit-0.0.1.tar.gz.

File metadata

  • Download URL: cubeit-0.0.1.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cubeit-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2f66f2c0935dafd43619f2f628b1d933e74c8e8ac157b490064f79cfa71c733d
MD5 b517fd17a545bc1ea35e5fea9fb1a45e
BLAKE2b-256 8ea90f26b80d6770e23c59a17b52ce91386051c5c898ff2f8b8a424609e3406a

See more details on using hashes here.

File details

Details for the file cubeit-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cubeit-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 31.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cubeit-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f07c9aec4af5b3f48b3131cc8bca9a8032ebc30e897d9812b86537b48b24bee7
MD5 a56358bf7066b077feb7ac127b4b1bcf
BLAKE2b-256 4115e025b951beca137d92eaf27736d6519323480e5631bbb1ed9cdf0f713bd6

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