Skip to main content

A package that allows game developers to integrate quantum circuit in their pygame-based quantum games.

Project description

Quantum Circuit Game Engine

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.
  • All configurations in one place in the config.py file.
  • 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, and GATE_TILE_HIEGHT in the config.py file.
  • Easily change controls by changing keys in the handle_input() method of the QuantumCircuitGrid class.

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.😁

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://jaisarita.vercel.app/ ☄️

Installation

pip install qcge

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.

You can run your quantum circuit on BasicAer Simulator by using this function:

def run_quantum_circuit(self, quantum_circuit):
        simulator = BasicAer.get_backend("statevector_simulator")
        quantum_circuit.measure_all()
        transpiled_circuit = transpile(quantum_circuit, simulator)
        counts = simulator.run(transpiled_circuit, shots=1).result().get_counts()
        measured_state = int(list(counts.keys())[0], 2)
        return measured_state

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, and gate_dimensions (= [GATE_TILE_WIDTH, GATE_TILE_HIEGHT]) to the qcge.QuantumCircuitGrid class as parameters.
  • You can change UI colors by passing optional parameters background_color, wire_color, and gate_phase_angle_color to the qcge.QuantumCircuitGrid class 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: 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

qcge-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

qcge-1.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file qcge-1.0.1.tar.gz.

File metadata

  • Download URL: qcge-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for qcge-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1e66f0e15d8b9aa20ed0124f8befadab50cf86ae2f3138d5b15c12d0dc8d9b0d
MD5 329c61a1eb7a629afb7b81d5ca6335dd
BLAKE2b-256 18fa24b41f5d7146e138276738dcd47d236c9e8983356d9b18ec152f01d672f5

See more details on using hashes here.

File details

Details for the file qcge-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: qcge-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for qcge-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 399dd8f0ec643b3ae6ec59ee618fc7b897255a206d35a638303ed1bde4028461
MD5 03a19ad704ab2c62377596bd4260fd1b
BLAKE2b-256 8b233858b84bc66fe785a102040bea5026582fd686e6bc5aeccd2180f3bf8753

See more details on using hashes here.

Supported by

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