Hello quantum world

Let's start

Writing and running your own algorithm on our platform is quite straightforward. As a registered user you can start programming by clicking MY QI from our homepage. Anonymous use of Quantum Inspire is not possible.

This will bring you to our editor, where you can write your quantum algorithm. You can run the code on our emulator backend or hardware backends and examine the results.

Please note: before running our examples or any code on one of the quantum inspire backends, pelase carefully check the constraints/requirements for that specific backend. For example, Starmon-7 backend would return an error for cQASM qubit[2] q,since it currently requires the user to delcare all 7 qubits as qubit[7] q.

Examine the code

The algorithm shows how to entangle two qubits using the Hadamard gate and CNOT gate. Under the advanced topics you will find more elaborate code examples.

The algorithm is written in cQASM. When you are writing more complex algorithms, you need to understand the detailed sematics and syntax of cQASM.

The file starts with the specification of the cQASM version on line 1. This line should always be present.

Line 3 is a single line comment. A single-line comment is prefixed by two forward slashes // and finishes with the new line. Use comments to document your code, so that someone else can understand what you were trying to do (note that that someone else could also be your future self).

Line 4 defines the size of the qubit register. In this simple example, two qubits are used. Each qubit in the register is identified by its index. The first qubit has index 0 and the second qubit has index 1. Make sure your qubit register does not define more qubits than used by your algorithm. The memory allocated for your algorithm is determined by this number and execution time is optimal when these numbers match.

Line 5 defines the size of the classical bit register that is used to store the outcome of qubit state measurements. Unlike in Quantum Inspire 1.0, the bit register is independent from the qubit register and can have an arbitrary size. This allows you to store for instance the results of intermediate measurements.

In line 8 we perform a Hadamard gate on qubit 0. The Hadamard gate is a single-qubit operation that brings the basis state 0|0\rangle to 00+112\frac{\vert 00 \rangle + \vert 11 \rangle}{\sqrt{2}}.

In line 11 we use a two-qubit operation to entangle both qubits. The CNOT operation flips the second qubit if the first qubit is in 1|1\rangle state and it does nothing on the second qubit if the first qubit is in 0|0\rangle state. Since the first qubit is in a superposition state, it both flips and doesn't flip the second qubit, bringing the full system in the entangled state 0+12\frac{\vert 0 \rangle + \vert 1 \rangle}{\sqrt{2}} which is one of the Bell states.

Finally, in lline 14, we measure the state of qubits 00 and 11 in bit registers 00 and 11.

Visualization of the algorithm

The corresponding circuit diagram is shown beneath the editor pane. Standard color coding is used in both the editor and the visualizer.

Export visualization

File format
Layout
Theme

The circuit is automatically and real-time rendered from the code. The editor also automatically checks your code for obvious errors such as syntax errors, multiple operations on the same qubit at the same time, out-of-range errors etc.

Running the algorithm

Now it's time to execute this algorithm on the Quantum Inspire emulator and examine the results.

When you are a novice in quantum algorithms, results may sometimes surprise you. In this example, the qubits are in an entangled state. You could almost say that, just before the measurement, both qubits are in 0|0\rangle state OR both qubits are in 1|1\rangle state (although this is a simplified explanation of the more complex physical reality).

At the top right you find the RUN button to initiate the execution of the algorithm. When you click on RUN you have to select the file that needs to be executed. When you just created your fisr algorithm you can only select one, namely source.cq. You can add a comment or message to this job. And you can select the backend on which this quantum circuit needs to be executed. Only backends that are currently online can be selected. You can also change the number of shots, which is the number of times the quantum circuit will be executed. We can choose 16 shots to begin with.

When you execute the algorithm, it will be scheduled in a queue. The waiting time depends on the length of the queue, your position in the queue and the time needed to run the algorithm. When your algorithm is executed, all shots will be executed directly after one another.

While your algorithm is scheduled to run, you can return to the editor, change the algorithm and execute another run.

Examining the results

Let's take a look at what our original algorithm produced.

If you click on Results a list of the scheduled, running and finished jobs is shown, sorted from newest to oldest. By clicking on Editor, you can always return to the editor. By now, the algorithm has probably finished. The status of each job shown on the screen can be updated by refreshing your browser (e.g. clicking F5 on most browsers).

When you open one of the results a histogram will be shown looking like this, although the exact values will probably be different:

0.438
00
0.563
11
1.0
0.8
0.6
0.4
0.2
0.0

When we measure a qubit, the result can be a 0 or a 1. In quantum inspire, the results of qubit measurements are stored in the bit register. What the histogram shows is not the final state of the qubits, but what the contents of the binary register is when the qubits are measured.

The chart shows a histogram over all shots of the state of the bit register at the end of the algorithm. In the example histogram above, the bit register was 0000 for 44% of the shots, and 1111 for 56% of the shots. The rightmost bit is the measurement value of the measured qubit with the lowest index (in this case q[0]). The leftmost bit is the measurement value of the measured qubit with the highest index (in this case q[1]).

The results show, that whenever the result of the measurement on q[0] was 00, the result of the measurement on q[1] was also 00. And, whenever the result of the measurement on q[0] was 11, the result of the measurement on q[1] was also 11, exactly what we expected.

By clicking Run we can execute another run of the algorithm, which could give a result like this:

0.500
00
0.500
11
1.0
0.8
0.6
0.4
0.2
0.0

Besides the histogram data of the bit register, the results pane also shows date and time of the execution, the execution duration, the number of shots and a unique identifier of the job.

This is all the basic information you need to write and run your own algorithms! Go ahead and enjoy!

Ready for more? Our Quick guide gives you more information on all kinds of extra functionlaity of the editor, details on how to steer compilation, managing your account and managing your projects. Expert users can go to our list of Advanced topics to find more info on our SDK, how to create more complex algorithms, optimize quantum circuits etc.

Enjoy !