Package: qcge
Quantum Circuit Game Engine for Pygame-based Quantum GamesThis 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 theQuantumCircuitGridclass stored in thequantum_circuit.pyfile.This Quantum Circuit was originaly created for theQPong Gamedeveloped byJunye Huangin the12 Days of Qiskit Program. I created this engine by re-writing its code locatedhereto 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 theconfig.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 adjustingQUANTUM_CIRCUIT_TILE_SIZE,GATE_TILE_WIDTH, andGATE_TILE_HIEGHTin theconfig.pyfile.Easily change controls by changing keys in thehandle_input()method of theQuantumCircuitGridclass.If this project is helpful for you or you liked my work, consider supporting me throughKo.fi🍵. Also, kindly consider giving a star to this repository.😁About meI 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/☄️InstallationpipinstallqcgeUsageYou can use it simply by creating an object of theQuantumCircuitGridclass stored in thequantum_circuit.pyfile. The constructor ofQuantumCircuitGridtakes 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:defrun_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)returnmeasured_stateConfigurationsAll the configurations for Quantum Circuit can be done in theconfig.pyfile. The controls of the quantum circuit in the game can be changed from the defaults mentioned below by changing keys in thehandle_input()method of theQuantumCircuitGridclass.You can change the size of Quantum Circuit by passing optional parameterstile_size, andgate_dimensions(= [GATE_TILE_WIDTH, GATE_TILE_HIEGHT]) to theqcge.QuantumCircuitGridclass as parameters.You can change UI colors by passing optional parametersbackground_color,wire_color, andgate_phase_angle_colorto theqcge.QuantumCircuitGridclass as parameters.Default values of these optional parameter are:tile_size=36gate_dimensions=[24,24]background_color='#444654'wire_color='#ffffff'gate_phase_angle_color='#97ad40'Game Controls for Building Quantum CircuitW, 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:PressC Keyto convert the X, Y, Z, or H gates into CX, CY, CZ, and CH gates respectively, and then pressR KeyandF Keyto 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 Keydecreases the rotation angle by π/8 andE Keyincreases the rotation angle by π/8.