Skip to main content

A pure NumPy quantum circuit simulator — no heavy dependencies

Project description

⚛️ CirQit

A pure NumPy quantum circuit simulator — no Qiskit, no PennyLane, no heavy deps.

pip install cirqit

Features

  • ✅ 20+ quantum gates (H, X, Y, Z, CNOT, Toffoli, RX, RY, RZ, SWAP, iSWAP, CZ, CRX, CRY, CRZ, CP, U3, SX, P...)
  • ✅ Custom statevector simulator (pure NumPy backend)
  • ✅ Noise models: Depolarizing, BitFlip, PhaseFlip, AmplitudeDamping, PhaseDamping, ThermalRelaxation, ReadoutError
  • ✅ ASCII + Matplotlib circuit visualization
  • ✅ Measurement histogram plots
  • ✅ Bloch sphere visualization
  • ✅ Built-in algorithms: Bell, GHZ, QFT, Grover, Deutsch-Jozsa, Bernstein-Vazirani, Teleportation, Phase Estimation
  • ✅ Circuit composition, inverse, copy
  • ✅ Custom unitary gate support
  • ✅ Only requires numpy + matplotlib

Quick Start

from cirqit import QuantumCircuit

# Bell state
qc = QuantumCircuit(2)
qc.h(0)
qc.cnot(0, 1)
qc.measure_all()

result = qc.run(shots=1024)
print(result)
# {'00': 512, '11': 512}

qc.draw()           # ASCII circuit
qc.draw('mpl')      # Matplotlib circuit
qc.plot_histogram(result)

Gates

qc = QuantumCircuit(3)

# Single-qubit
qc.h(0)          # Hadamard
qc.x(1)          # Pauli-X
qc.y(2)          # Pauli-Y
qc.z(0)          # Pauli-Z
qc.s(1)          # S gate
qc.t(2)          # T gate
qc.sx(0)         # √X gate
qc.rx(1.57, 0)   # Rotation-X
qc.ry(0.78, 1)   # Rotation-Y
qc.rz(3.14, 2)   # Rotation-Z
qc.p(1.57, 0)    # Phase gate
qc.u(1.57, 0.78, 1.57, 1)  # U3 gate

# Two-qubit
qc.cnot(0, 1)    # CNOT
qc.cz(0, 1)      # Controlled-Z
qc.swap(1, 2)    # SWAP
qc.crx(1.57, 0, 1)  # Controlled-RX

# Three-qubit
qc.ccx(0, 1, 2)  # Toffoli
qc.cswap(0, 1, 2)  # Fredkin

Noise Models

from cirqit.noise import NoiseModel, DepolarizingChannel, AmplitudeDampingChannel

nm = NoiseModel()
nm.add_gate_error('h', DepolarizingChannel(0.01))
nm.add_gate_error('x', AmplitudeDampingChannel(0.05))
nm.add_readout_error(p0_given_1=0.02, p1_given_0=0.02)

qc = QuantumCircuit(2)
qc.h(0).cnot(0, 1).measure_all()
qc.set_noise_model(nm)

noisy_result = qc.run(shots=2048)

# Presets
from cirqit.noise import basic_depolarizing, realistic
nm = realistic(p_gate=0.005, p_readout=0.02)

Built-in Algorithms

from cirqit.algorithms import (
    bell_state, ghz_state, qft, grover_diffusion,
    deutsch_jozsa, bernstein_vazirani, teleportation,
    phase_estimation, random_circuit
)

# Bell state
bell = bell_state('00')
bell.measure_all()
print(bell.run(1024))

# QFT on 4 qubits
qft4 = qft(4)
print(qft4)

# Deutsch-Jozsa
dj = deutsch_jozsa('balanced', n=3)
print(dj.run(1))

# Bernstein-Vazirani — find secret string
bv = bernstein_vazirani('1011')
print(bv.run(shots=1))

Statevector & Bloch Sphere

qc = QuantumCircuit(1)
qc.h(0)

sv = qc.statevector()
print(sv)
# StateVector (1 qubits):
#   |0⟩: 0.7071+0.0000j  (p=0.5000)
#   |1⟩: 0.7071+0.0000j  (p=0.5000)

qc.plot_bloch(qubit=0)

Circuit Operations

# Inverse
inv = qc.inverse()

# Compose
combined = qc.compose(other_circuit)

# Info
print(qc.depth())
print(qc.count_ops())
print(qc.probabilities())

License

MIT © Muhammad

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

cirqit-0.1.3.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

cirqit-0.1.3-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file cirqit-0.1.3.tar.gz.

File metadata

  • Download URL: cirqit-0.1.3.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for cirqit-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a429eceadde206a14e832a58cba4f776397fd8222729039e5d0fe41c4dbe33e4
MD5 906527506b181c53ce1538be2622c299
BLAKE2b-256 6fee2582d1289951994238fc274e9c1f56ba69437873cc87352643cd71d2de17

See more details on using hashes here.

File details

Details for the file cirqit-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: cirqit-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.8

File hashes

Hashes for cirqit-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c9f34c60cb033a0b632a88a9087e3db0b3f76975fe82b3ebbfec117ea176f55c
MD5 cf8e450d7cc45c09c1a5201b01128d77
BLAKE2b-256 79af133eb07d62fe656041c63bd69e95b620ae4c228153a6181befd4d2a930f9

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