This page provides access to the source code of the Quantum Gate Music Generator, a system that translates quantum gate operations into musical output using Qiskit and Python.
The tool features a GUI interface for designing quantum circuits and hearing their musical interpretation in real time.
Citation:
Souma, S. (2022). Exploring the Application of Gate-Type Quantum Computational Algorithm for Music Creation and Performance. In: Miranda, E.R. (eds) Quantum Computer Music. Springer, Cham. https://doi.org/10.1007/978-3-031-13909-3_5
A Graphical Interface for Quantum Music Creation :This visual interface enables users to design quantum circuits using buttons, sliders, and gate selections, and instantly hear their musical outputs. Multiple modes are supported, including note-based playback, chord progression, and quantum game strategies. Designed as part of an exploratory project on quantum-based musical expression, this system bridges quantum computation and real-time sound synthesis.
Mode 1–5: These are the mode selection buttons. The parameter Nbit_note shown here indicates the number of qubits used per note, depending on the selected mode. (For details, see the explanation for each mode below.)
Nnotes: The number of notes along the time axis. In Modes 1–4, this corresponds to the number of active columns of radio buttons in the center of the GUI.
In Mode 5 (which applies quantum game theory to two-player music generation), two players each play a note at every time step. Therefore, for example, if Nnotes = 4, the number of radio button columns used becomes Nnotes × 2 = 8. (Further details are provided in the Mode 5 section.)
Nshots: The number of measurement shots.
Measurement: Executes quantum measurement.
Playback: Plays back the notes corresponding to the latest measurement results.
Stop Playback: Stops playback during multiple-shot playback. Playback halts at the end of the current shot sequence.
Save GUI State: Saves the current GUI configuration.
Load GUI State: Loads a previously saved GUI configuration.
The radio buttons and sliders below the main controls configure the quantum gates applied to each note along the time axis (i.e., column-wise, from left to right).
The function and interpretation of these gates vary depending on the selected mode, and are explained within the individual mode descriptions.
The white panel at the bottom displays the measured bitstrings.
The rightmost digit in each bitstring corresponds to the first note in time.
The horizontal length of each bitstring is given by Nbit_note × Nnotes, depending on the mode.
Vertically, each row corresponds to a distinct measurement result among the Nshots performed.
Mode 1 (Stochastic Note Generation Model)
In Mode 1, each musical note is encoded using a single qubit. The quantum state of the qubit is measured along a time-varying axis on the Bloch sphere, with the measurement angle around the Y-axis (in x-z plane) specified by the user through the GUI.
The measurement outcome determines which note is played:
If the result is 0, the note corresponds to one of the following: G, G, D, or E.
If the result is 1, it corresponds to F♯, D♭, A♭, or E♭, which are tritone pairs to the former on the circle of fifths.
Transitions between notes are mediated by CNOT gates, linking each note to the next. This design allows for entangled and superposed quantum states along the timeline, depending on the chosen measurement axes.
Upon measurement, one of the superposed possibilities is realized and played as sound. When increasing the number of shots, the sequence of non-equivalent measurement outcomes is played serially, producing a probabilistically-generated melody.
Example of GUI settings in Mode 1.
Here, Nnotes is set to 4, so the first four columns of radio buttons in the center are active. Gates 1, 2, 3, and 4 are selected, corresponding to G/F♯, G/D♭, D/A♭, and E/B♭, respectively. Nshots is set to 10, and in this case, six non-equivalent measurement outcomes are obtained (displayed in the lower panel of the GUI). The notes corresponding to these outcomes are played in serial order, with the rightmost digit played first.
The quantum circuit shown above corresponds to the settings configured in the GUI for Mode 1.
When the "Use circuit drawer" option is enabled in the interface, this circuit diagram is automatically generated and saved as a file named circuit_diagram.png.
Example musical score generated using the quantum circuit in Mode 1.
Mode 2 (Stochastic Note name/Note value Generation Model)
In Mode 2, each musical note is encoded using two qubits.
The first qubit corresponds to the note duration (note value). If the measurement result of this second qubit is:
0, the note is assigned a quarter note (♩)
1, the note is assigned a half note (𝅗𝅥)
The second qubit determines the pitch of the note in the same way as in Mode 1—by measuring the qubit state along a time-varying axis on the Bloch sphere (around the Y-axis), resulting in one of two complementary notes related by a tritone interval.
As in Mode 1, transitions between qubits are mediated by CNOT gates, but in this case the sequence is structured as follows:
Duration of note 1 → Pitch of note 1 → Duration of note 2 → Pitch of note 2 → ..., with a chain of CNOTs connecting them in time.
This arrangement creates quantum entanglement not only between pitches but also between pitch and duration, resulting in complex quantum correlations between musical parameters.
Upon measurement, one of the superposed possibilities is realized and played as sound. When increasing the number of shots, the sequence of non-equivalent measurement outcomes is played serially, producing a probabilistically-generated melody.
Example of GUI settings in Mode 2:
Here, Nnotes is set to 4, so the first four columns of radio buttons in the center area of the GUI are active—just as in Mode 1. The user has selected Gates 1, 3, 4, and 6, which correspond to the note pairs C/F♯, D/A♭, E/B♭, and G/D♭, respectively. Nshots is set to 10, and in this particular case, all 10 measurement results were non-equivalent, as shown in the lower panel of the GUI (although in general, the number of unique outcomes tends to be smaller than the number of shots).
Unlike Mode 1, each note in Mode 2 is represented by two qubits—one for pitch and one for duration—so each bitstring obtained from measurement contains Nnotes × 2 = 4 × 2 = 8 bits.
For example, in the first measurement result, the rightmost 6 bits (representing the first three notes in time) are:
The quantum circuit shown above corresponds to the settings configured in the GUI for Mode 2.
Example musical score generated using the quantum circuit in Mode 2.
Mode 3 (Chord generation)
In Mode 3, each musical note is represented using three qubits. The quantum states |000⟩ to |111⟩ are mapped respectively to a rest (|000⟩) and to the notes F, C, G, D, A, E, and B, in ascending order of perfect fifths (e.g., |001>=|F>, |010>=|C>, |011>=|G>, |100>=|D>, |101>=|A>, |110>=|E>, |111>=|B>). This assignment is based on the circle-of-fifths concept in music theory. Each of the three qubits contributes additively to the pitch identity: the least significant bit corresponds to a fifth shift (V degree), the second to a second upward shift (II degree), and the most significant to a third upward shift (III degree). In this way, the seven diatonic chords (from I_M7 to VII♭5_m7) can be implemented by applying appropriate quantum gates that shape the superposition to include only the pitches belonging to a given chord. Upon measurement, one of the constituent notes of the chord is probabilistically realized and played. By extending this approach, it becomes possible to represent not only individual chords but also transitions between them, using quantum entanglement to encode harmonic correlations. This opens up a novel paradigm in which musical progressions are generated through the interplay between quantum coherence and tonal logic.
(Left) An example of the GUI input for Mode 3. Here the chord progression is IM7-->IIm7-->V7-->IM7.
(Top) Example musical score generated using the quantum circuit in Mode 3.
Mode 4 (Quantum "Phrase" modulation model)
Mode 4 also uses three qubits to represent pitch information through a mapping onto the circle of fifths, as in Mode 3. However, instead of associating notes with chord names, Mode 4 allows users to directly input the desired pitch names. For each note in the temporal sequence, a dedicated quantum circuit is prepared such that, when measured, it deterministically yields the specified pitch. This ensures that, initially, each note collapses to the user-defined value upon measurement. Then, between each successive pair of notes, phase modulation is applied via quantum gates. This introduces meaningful interactions between adjacent notes, allowing the pitch of a given note to be influenced by the preceding one. As a result, the actual outcome of the later notes may differ from the originally assigned pitch, despite being initialized to those values. The modulation is not random or classically perturbed, but rather introduced coherently at the quantum state level. Upon measurement, a variety of melodic outcomes may be generated probabilistically. This kind of inter-note modulation corresponds to transformations within the space of superposed possibilities prior to measurement—what can be thought of as a meta-space—and offers a novel approach to musical modulation, understood as transformations in musical context and key.
Mode 5 (Two Players Model Based on Quantum Game Theory)
In Mode 5, as in Modes 1 and 2, each note is represented by a single qubit. That is, the user specifies the measurement axis on the circle of fifths, thereby shaping the flow of musical possibilities as an act of composition, while the actual sounding notes are determined probabilistically through measurement. What distinguishes Mode 5 from Modes 1 and 2 is the introduction of two players. Each player generates a tone, but before the note is measured and heard, the two players' quantum states are entangled in the quantum space. This entanglement process—an inherent feature of the system rather than something directly manipulated by the user—creates a shared quantum state between the two performers. After this entanglement, each player independently chooses a measurement strategy, which ultimately determines the observed note. However, the strategy chosen by one player not only affects their own note, but may also influence the outcome of the other player’s measurement. The same applies symmetrically, so the two players mutually affect each other's sonic output. This is not to say that their choices distort the intended sounds; rather, their strategic interactions serve as a creative process that collaboratively shapes the musical output. As a result, the music that emerges may transcend the individual intentions of either player. This system can be likened to a jazz session, where mutual inspiration leads to spontaneous, co-created expression. Thus, Mode 5 offers a novel paradigm in which composition and performance are unified, while also enabling a new interpretation of ensemble or polyphonic interaction from the perspective of quantum entanglement.