Quantum Circuit Game Engine - build pygame quantum-circuit games that run with real Qiskit on desktop or a dependency-free simulator in the browser.
Project description
Quantum Circuit Game Engine for Pygame-based Quantum Games
This is a Quantum Circuit Game Engine for integrating Quantum Circuits into your Pygame-based quantum game. You can use it simply by creating an object of the QuantumCircuitGrid class stored in the quantum_circuit.py file.
This Quantum Circuit was originaly created for the QPong Game developed by Junye Huang in the 12 Days of Qiskit Program. I created this engine by re-writing its code located here to make it modular and abstract for easy use with any quantum game.
The features I have included are:
- Modular and Abstract Code.
- Pluggable execution backends (new in v2): run circuits with real Qiskit on the desktop, or a pure-Python statevector simulator (zero third-party dependencies) that also runs in the browser (pygbag/WebAssembly), where Qiskit cannot. A numpy simulator is also available for desktop use. The engine auto-selects the best backend.
- Browser-safe by design. The pure-Python backend imports nothing beyond the standard library. This matters: importing numpy inside a pygbag/WebAssembly build breaks the SDL display (grey screen / "video driver did not add any displays"), so the browser path must stay numpy-free.
import qcgeis numpy-free (the numpy/qiskit backends are lazy), andbackend="auto"resolves to the pure-Python simulator in the browser automatically. - Qiskit is optional.
pip install qcgeships the simulators;pip install qcge[qiskit]adds the real Qiskit backend (Qiskit 2.x; 1.x is end-of-life). - All configurations in one place in the
config.pyfile. - Developers can create a Quantum Circuit for any number of qubit/wires and circuit width (max. number of gates which can be applied in a wire) of their choice.
- Easy to change UI by replacing color configs and graphics for gates with those of your choice.
- Easy to change the size of Quantum Circuit by adjusting
QUANTUM_CIRCUIT_TILE_SIZE,GATE_TILE_WIDTH, andGATE_TILE_HIEGHTin theconfig.pyfile. - Easily change controls by changing keys in the
handle_input()method of theQuantumCircuitGridclass.
If this project is helpful for you or you liked my work, consider supporting me through Ko.fi🍵. Also, kindly consider giving a star to this repository.😁
Roadmap
The v2 backend system (a backend-agnostic circuit IR + a pluggable QuantumBackend
strategy) is designed so new execution targets slot in without touching any game or
UI code. Planned next:
- Real quantum hardware backend. An
IBMBackend(backend="ibm", optional extraqcge[ibm]) built onqiskit-ibm-runtime'sSamplerV2, where the player supplies their own IBM Quantum API token/credits and runs the circuit they built on a real QPU. Because hardware jobs are queued and take seconds-to-minutes, this is intended as an explicit "run on real hardware" action (async, result shown when ready) rather than the real-time game loop. Hardware returns measurement counts (no statevector), which the uniformSimulationResultalready accommodates. Desktop-only, since a browser/WebAssembly build cannot securely hold credentials. - More simulator backends (e.g.
qiskit-aerfor noisy/shot-based simulation). - Additional gates and an explicit measurement node in the grid UI.
About me
I am Ashmit JaiSarita Gupta, an Engineering Physics Undergraduate passionate about Quantum Computing, Machine Learning, UI/UX, and Web Development. I have worked on many projects in these fields, participated in hackathons, and am a part of great organizations in these fields. You can explore more about me, my work, and my experience at various organizations through my portfolio website: https://ashmitjsg.vercel.app/ ☄️
Installation
# core engine + dependency-free simulator (works everywhere, incl. browser builds)
pip install qcge
# add the real Qiskit backend for desktop/notebook use
pip install qcge[qiskit]
Requires Python ≥ 3.9. The
qiskitextra pulls Qiskit ≥ 2.0.
Usage
You can use it simply by creating an object of the QuantumCircuitGrid class stored in the quantum_circuit.py file. The constructor of QuantumCircuitGrid takes these values as argument:
position: Position of the Quantum Circuit in the game window.num_qubits: Number of Qubits in the Quantum Circuit.num_columns: Circuit width (max. number of gates which can be applied in a wire) of their choice.tile_size(Optional, Default Value = 36): Size of single tile unit of the Quantum Circuit. It is the square area containing single gate in the quantum circuit.gate_dimensions(Optional Default Value = [24, 24]): [Width, Height] of quantum gates.background_color(Optional Default Value = '#444654'): Background Color of the Quantum Circuit.wire_color(Optional Default Value = '#ffffff'): Color of Quantum Wire in the Quantum Circuit.gate_phase_angle_color(Optional Default Value = '#97ad40'): Color to represent phase angle of Rotation Gates.backend(Optional, Default"auto"): execution backend -"auto","qiskit","python"/"sim", or"numpy"(see below).assets_path(Optional): folder to load gate images from, if you want to ship your own gate art instead of the bundled graphics.movement_keys(Optional, Default"both"): which keys move the circuit cursor -"wasd","arrows", or"both". Use"arrows"to free the S key for the S gate.allowed_gates(Optional, DefaultNone= all): a list/tuple restricting the gate palette the player may place, e.g.("H", "X", "CTRL"). Useful for tutorial levels. Tokens come fromSUPPORTED_INPUT_GATES.
Running (simulating) the circuit
The grid simulates itself through the selected backend - no Qiskit boilerplate, no
removed BasicAer/execute:
from qcge import QuantumCircuitGrid
# backend="auto" (default) -> Qiskit if installed, else the pure-Python simulator
grid = QuantumCircuitGrid(position=(0, 0), num_qubits=2, num_columns=8)
# ...player builds a circuit on the grid...
statevector = grid.get_statevector() # complex amplitudes (little-endian, Qiskit order)
counts = grid.get_counts(shots=1024) # {"00": 512, "11": 512, ...}
result = grid.run() # full SimulationResult (probabilities/sampling/most_likely)
measured = int(result.most_likely(), 2)
Choose or switch the backend explicitly:
QuantumCircuitGrid(..., backend="qiskit") # real Qiskit (needs qcge[qiskit])
QuantumCircuitGrid(..., backend="python") # pure-Python simulator (browser-safe, zero deps)
QuantumCircuitGrid(..., backend="sim") # alias for the pure-Python simulator
grid.set_backend("numpy") # numpy simulator (desktop convenience)
from qcge import available_backends, get_backend
available_backends() # e.g. ["qiskit", "python", "numpy"]
# "auto" prefers Qiskit on desktop and the pure-Python simulator otherwise; it
# never auto-selects numpy, so the browser path stays numpy-free.
You can still get a raw qiskit.QuantumCircuit when needed (requires the qiskit extra):
qc = grid.create_quantum_circuit() # or grid.to_ir() for the backend-agnostic IR
Configurations
All the configurations for Quantum Circuit can be done in the config.py file. The controls of the quantum circuit in the game can be changed from the defaults mentioned below by changing keys in the handle_input() method of the QuantumCircuitGrid class.
- You can change the size of Quantum Circuit by passing optional parameters
tile_size, andgate_dimensions(= [GATE_TILE_WIDTH, GATE_TILE_HIEGHT]) to theqcge.QuantumCircuitGridclass as parameters. - You can change UI colors by passing optional parameters
background_color,wire_color, andgate_phase_angle_colorto theqcge.QuantumCircuitGridclass as parameters.
Default values of these optional parameter are:
tile_size = 36
gate_dimensions = [24, 24]
background_color = '#444654'
wire_color = '#ffffff'
gate_phase_angle_color = '#97ad40'
Game Controls for Building Quantum Circuit
- W, A, S, D Keys (or the Arrow keys, configurable via
movement_keys): Move the "Circuit Cursor" in the Quantum Circuit to the place where you want to add a gate in the circuit. - Backspace Key: Remove the gate present at the Circuit Cursor.
- Delete Key: Clear the Quantum Circuit, i.e., remove all gates from the Quantum Circuit.
- X Key: Add X Gate to the quantum circuit.
- Y Key: Add Y Gate to the quantum circuit.
- Z Key: Add Z Gate to the quantum circuit.
- H Key: Add H Gate to the quantum circuit.
- C, R, E Keys: Press C Key to convert the X, Y, Z, or H gates into CX, CY, CZ, and CH gates respectively, and then press R Key and F Key to the control to qubit above or below respectively.
- Q and E Keys: To convert X, Y, and Z into RX, RY, and RZ gates respectively. Q Key decreases the rotation angle by π/8 and E Key increases the rotation angle by π/8.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qcge-2.0.1.tar.gz.
File metadata
- Download URL: qcge-2.0.1.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
343ef22d466ac57c0e5ea841c0450376f0e0a13ed918fd70920c217324e53419
|
|
| MD5 |
3247994fcc58591f2dd34a155ea2ff03
|
|
| BLAKE2b-256 |
f285a837074acff3a37cfb596ff4470ec58b35121d8490719d50bf99201a6d59
|
Provenance
The following attestation bundles were made for qcge-2.0.1.tar.gz:
Publisher:
publish-to-pypi.yml on ashmitjsg/Quantum-Circuit-Game-Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qcge-2.0.1.tar.gz -
Subject digest:
343ef22d466ac57c0e5ea841c0450376f0e0a13ed918fd70920c217324e53419 - Sigstore transparency entry: 1782606593
- Sigstore integration time:
-
Permalink:
ashmitjsg/Quantum-Circuit-Game-Engine@35f1c6b9e0af7263dc1529058061338188539630 -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/ashmitjsg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@35f1c6b9e0af7263dc1529058061338188539630 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qcge-2.0.1-py3-none-any.whl.
File metadata
- Download URL: qcge-2.0.1-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d724f86cd168a49dd8dfb6946f68d216ac502278dda1c9468cd93ba2371dbccc
|
|
| MD5 |
c5d5cfa593d9762b93e1ac63526de67a
|
|
| BLAKE2b-256 |
5a25441fdc0391b64c9bcf81fdcbb2e2f167e10f4668ebb02079e713dbd6dab3
|
Provenance
The following attestation bundles were made for qcge-2.0.1-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on ashmitjsg/Quantum-Circuit-Game-Engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qcge-2.0.1-py3-none-any.whl -
Subject digest:
d724f86cd168a49dd8dfb6946f68d216ac502278dda1c9468cd93ba2371dbccc - Sigstore transparency entry: 1782606746
- Sigstore integration time:
-
Permalink:
ashmitjsg/Quantum-Circuit-Game-Engine@35f1c6b9e0af7263dc1529058061338188539630 -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/ashmitjsg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@35f1c6b9e0af7263dc1529058061338188539630 -
Trigger Event:
push
-
Statement type: