Simple Quantum Gates Card Game using Python and Q#

Lucy Zhang
3 min readDec 18, 2020

with @arjunsub00

How we made a simple quantum gates card game during the Microsoft Garage internship with Q#.

This article is part of the Q# Advent Calendar 2020. Stay tuned for new posts on quantum computing each day of this Christmas month!

A list of 10 different quantum gates, including Pauli-X, Pauli-Y, Pauli-Z, Hadamard, Phase(S,P), T, CNOT, CZ, and SWAP.

Overview

During the Microsoft Garage Internship in 2020, specifically during Microsoft’s Annual Hackathon, Arjun Subramonian and I created a simple quantum card game. This is a simple two-player card game that illustrates the functionality of basic single and two-qubit quantum gates. After playing this game, one will have developed a foundation for building quantum circuits and an interest in learning about more complex gates and quantum algorithms.

Our motivation to build this game was twofold: to learn more about the Q# programming language, and to explore the educational space of quantum and computer science. The game runs in a Jupyter Notebook, calling a Python and Q# backend, respectively. We hope that this game can serve as an introduction to students of any age and background, especially underrepresented youth.

Click here to play the game! (If the Binder link doesn’t work, you can run the notebook from the source code)

Game Rules

  • Both players begin with 50 points
  • There are two qubits in the center, which both start off in the state (1 + 0i)|0> + (0 + 0i)|1>
  • Players take turns applying 2 operations (each card represents a gate, control, or SWAP operation) to the qubits at a time
  • Gates may be single or two-qubit gates, which allows players to learn about entanglement
  • If both qubits are measured to be 1, then the player gets a point, else if both qubits are measured to be 0, the player loses a point, otherwise the player neither gains nor loses any points
  • There is an element of probability because the qubits may be in a superposition of states. In this way, players will gain practice with amplitudes, since they must maximize the coefficient of the state which they want to measure (|1>)
  • The next player applies operations to the qubits in the non-collapsed state to which the previous player brought the qubits
  • The game ends when a player loses by hitting 0 points or a player wins by hitting 100 points

Going Forward

Currently, the game is merely a prototype, as the front end is quite minimal, and we only support a few gates. In future iterations, we hope to incorporate more different gates, and add more complexity depending on feedback.

Furthermore, the game does not currently simulate the decoherence-induced real-world noise introduced into quantum computers when measuring qubits, i.e. the loss of information from a quantum computer into its environment. In the future, we hope to include random noise in our game, which can cause unexpected measurements, thereby educating players about decoherence while adding some twists to the game!

We welcome all suggestions and feedback!

Source Code: https://github.com/zhang-lucy/quantum-game
Quantum Katas: https://github.com/microsoft/QuantumKatas
Garage Internship: https://careers.microsoft.com/us/en/job/870952/Internship-Opportunities-for-Students-Garage-Software-Engineer

--

--