Q&A

Last updated: August 18th, 2024.

About QCoder

What is QCoder?

QCoder is a new quantum programming contest platform launched in 2024.

Unlike traditional programming contests, QCoder presents problems that require the implementation of quantum algorithms that run on quantum computers.

I'm unfamiliar with quantum computing. What should I do?

We recommend starting by participating in the contest.

While you might find many parts confusing at first, you'll gradually understand the bigger picture as you solve problems and refer to the editorial provided.

QCoder aims to offer contests that can be enjoyed by everyone, from those who know nothing about quantum computing to experts.

How can I implement quantum algorithms?

Currently, we support the use of Qiskit, a quantum programming language (framework) that operates on Python.

Submitted programs are evaluated using a simulator, not an actual quantum computer.

*The editor on QCoder does not support autocompletion or linters. We recommend setting up a Qiskit environment on your local computer.

I want to study quantum computing. Do you have any recommended materials?

The following materials are recommended:

I want to know about upcoming contests and updates.

Please follow us on X (Twitter) and register on Google Calendar.

What kind of submission statuses are there?

The following submission results may be displayed:

  • AC (Accepted): The submission passed all test cases.
  • WJ (Waiting for Judging): The submission is waiting to be judged.
  • WA (Wrong Answer): The submission did not pass at least one test case.
  • QLE (Qubits Limit Exceeded): The number of qubits exceeded the limit.
  • DLE (Depth Limit Exceeded): The circuit depth exceeded the limit.
  • TLE (Time Limit Exceeded): The execution time exceeded the limit.
  • MLE (Memory Limit Exceeded): The memory usage exceeded the limit.
  • CE (Compilation Error): Some error occurred during the compilation.
  • RE (Runtime Error): Some error occurred during the program execution.
  • UME (Unauthorized Module Error): An unauthorized module was imported.
  • UGE (Unauthorized Gate Error): An unauthorized quantum gate was present in the circuit.
  • TOE (Time Out Error): A certain amount of time has passed without the submission being judged.

What libraries and modules can be used?

Currently, only the following Python modules are permitted for use.

If any modules other than these are imported, an UME (Unauthorized Module Error) will be displayed.

  • Standard Library
    • math (import math)
  • Qiskit
  • qiskit.circuit.library.standard_gates
    • Any class from this module can be imported. Examples of importable classes include:
      • HGate (from qiskit.circuit.library.standard_gates import HGate)
      • CXGate (from qiskit.circuit.library.standard_gates import CXGate)
      • MCPhaseGate (from qiskit.circuit.library.standard_gates import MCPhaseGate)
  • External library

What quantum gates can be used?

You are permitted to use quantum gates classified under Qiskit's standard gates as well as multi-control gates like the MCPhaseGate.

The use of gates that do not fall under these categories, such as the following, is prohibited and will display an UGE (Unauthorized Gate Error) if used:

Can I add extra quantum bits to the circuit?

Currently, users are not allowed to change the number of qubits in a quantum circuit.

There are plans for future updates to accommodate situations where auxiliary qubits (ancilla) are required for certain quantum algorithms to function as temporary memory.

Can I execute quantum circuits on my local computer?

You can execute quantum circuits that you have created on your own device.

For example, you can output the final state vector of a circuit using the following code:

Open
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
 
 
def solve() -> QuantumCircuit:
    qc = QuantumCircuit(1)
    # Write your code here:
 
    return qc
 
 
if __name__ == "__main__":
    qc = solve()
    print(Statevector(qc))

What is a Python compile error?

In Python, the source file is compiled into bytecode before code execution. This is usually done automatically at runtime, and the result is cached, but you can also manually compile using py_compile.

In QCoder, py_compile is performed before execution to prevent any impact on execution time.

What are the versions of Python and of the libraries?

Currently, submissions are judged on the judge server using Python 3.11.

Please refer to the requirements.lock file below for the versions of the libraries used in the judge environment.

Open
dill==0.3.8
mpmath==1.3.0
numpy==2.0.1
pbr==6.0.0
psutil==6.0.0
python-dateutil==2.9.0.post0
qiskit==1.1.1
qiskit-aer==0.14.2
rustworkx==0.15.1
scipy==1.14.0
six==1.16.0
stevedore==5.2.0
symengine==0.11.0
sympy==1.13.1
typing_extensions==4.12.2

QCoder regularly updates the judging environment, however backward compatibility is not guaranteed.

I am interested in QCoder's activities. How can I contribute to creating problems or operations?

We are looking for people who can contribute to problem creation (Writer) and operations, as well as sponsoring companies.

If you are interested, please feel free to contact us through the contact link.

About Quantum Computing

What is a Quantum State?

In quantum computing, computings are performed using "quantum bits" (qubits), which are the quantum equivalent of bits in classical computing.

The arbitrary state ψ\ket{\psi} of a single qubit can be expressed as a superposition of states 0\ket{0} and 1\ket{1} with coefficients a0a_0 and a1a_1 as follows:

ψ=a00+a11\ket{\psi} = a_0\ket{0} + a_1\ket{1}

In this manner, a qubit can exist in a probabilistic superposition of 0\ket{0} and 1\ket{1}, and it collapses to either 0\ket{0} or 1\ket{1} upon "measurement".

The coefficients a0a_0 and a1a_1 are complex numbers called "probability amplitudes". When ψ\ket{\psi} is measured, state 0\ket{0} is observed with probability a02|a_0|^2, and state 1\ket{1} is observed with probability a12|a_1|^2.

Since one of the states will always be observed upon measurement, the probability amplitudes a0a_0 and a1a_1 satisfy the normalization condition a02+a12=1|a_0|^2 + |a_1|^2 = 1.

This state of the qubit is referred to as a "quantum state".

Additionally, if we represent the states 0\ket{0} and 1\ket{1} as vectors like:

0=(10), 1=(01),\ket{0} = \begin{pmatrix} 1 \\ 0 \end{pmatrix},\ \ket{1} = \begin{pmatrix} 0 \\ 1 \end{pmatrix},

then the quantum state ψ\ket{\psi} can be represented as:

ψ=a00+a11=(a0a1).\ket{\psi} = a_0\ket{0} + a_1\ket{1} = \begin{pmatrix} a_0 \\ a_1 \end{pmatrix}.

This vector representation is known as the "state vector" of the quantum state.

Next, let's consider the quantum state of multiple qubits.

The arbitrary quantum state ψ\ket{\psi} of nn qubits can be expressed as a superposition of 2n2^n states as follows:

ψ=a00...0n+a110...0n+...+a2n11...1n=(a0a2n1)\ket{\psi} = a_0\ket{\underbrace{0...0}_n} + a_1\ket{\underbrace{10...0}_n} + ... + a_{2^n-1}\ket{\underbrace{1...1}_n} = \begin{pmatrix} a_0 \\ \vdots \\ a_{2^n - 1} \end{pmatrix}

As with the single-qubit case, the normalization condition a02+a12++a2n12=1|a_0|^2 + |a_1|^2 + \dots + |a_{2^n-1}|^2 = 1 holds.

For example, the quantum states of 2 qubits include 00\ket{00}, 12(00+11)\frac{1}{\sqrt{2}} (\ket{00} + \ket{11}), or 14(00+10+01+11)\frac{1}{\sqrt{4}}(\ket{00} + \ket{10} + \ket{01} + \ket{11}).

What is a Computational Basis State?

A computational basis state refers to a state of the form b0b1...bn1\ket{b_0b_1...b_{n-1}}, where bi=0,1b_i=0,1. Examples of computational basis states are: 0\ket{0}, 10\ket{10} or 111\ket{111}.

For example, the quantum state of 2 qubits

ψ=14(00+10+01+11)\ket{\psi} = \frac{1}{\sqrt{4}}(\ket{00} + \ket{10} + \ket{01} + \ket{11})

is a uniform superposition of the 2-qubit computational basis states 00\ket{00}, 10\ket{10}, 01\ket{01}, and 11\ket{11}.

Computational basis states can also be represented using decimal notation instead of binary notation, as in 0decimal=00binary, 1=10, 2=01, 3=11\underbrace{\ket{0}}_{\text{decimal}} = \underbrace{\ket{00}}_{\text{binary}},\ \ket{1} = \ket{10},\ \ket{2} = \ket{01},\ \ket{3} = \ket{11}.

What is a Quantum Gate?

In quantum computing, the concept of a "quantum gate" is used to manipulate quantum states.

For example, a quantum gate called "XX gate" inverts the computational basis state of a qubit.

0X11X012(0+1)X12(0+1)\begin{align} \ket{0} &\xrightarrow{X} \ket{1} \nonumber\\ \ket{1} &\xrightarrow{X} \ket{0} \nonumber\\ \frac{1}{\sqrt{2}}(\ket{0} + \ket{1}) &\xrightarrow{X} \frac{1}{\sqrt{2}}(\ket{0} + \ket{1}) \nonumber\\ \end{align}

Besides the XX gate, there are many other types of quantum gates.

Understanding the meaning and role of each quantum gate may be helpful in solving future problems.

What is an Oracle?

An oracle OO is a term used in quantum algorithms to refer to some operation treated as a black box.

By defining the interface (input and output) without considering the implementation of the oracle as a black box, the complexity of the upstream quantum algorithm can be evaluated by the number of oracle calls.

However, the oracle itself must also be implemented as a quantum circuit.

By defining some function ff with input and output as computational basis states, the oracle OO can be defined as follows:

  • When the input and output are the same state: Ox=f(x)O\ket{x} = \ket{f(x)}
  • When the input and output are different states: O(xy)=xyf(x)O(\ket{x} \otimes \ket{y}) = \ket{x} \otimes \ket{y \oplus f(x)}

Note that when applying the oracle, the function ff acts on all computational basis states appearing in the decomposition of the target quantum state.

Please also refer to the following web pages:

What is a Circuit Depth?

In quantum circuits, multiple quantum gates are stacked on each quantum bit in a manner similar to Tetris, describing "which quantum gate acts on which quantum bit in what order."

The circuit depth refers to the number of layers of quantum gates stacked in this manner.

circuit depth

(From Quantum Circuits - IBM Quantum Documentation)

Executing a quantum circuit can be thought of as applying these layers sequentially to the quantum bits, which can be interpreted as a metric similar to the time complexity of classical algorithms.

In QCoder, the return value of the depth function of Qiskit's QuantumCircuit class is treated as the depth of the circuit.

What is a Global Phase?

Consider a quantum state ψ\ket{\psi} and a quantum state ψ(θ)=eiθψ\ket{\psi(\theta)} = e^{i\theta}\ket{\psi} obtained by multiplying it by eiθ=cos(θ)+isin(θ)e^{i\theta} = \cos(\theta) + i\sin(\theta), where ii is the imaginary unit and θ\theta is some real number.

Here, ψ\ket{\psi} and ψ(θ)=eiθψ\ket{\psi(\theta)} = e^{i\theta}\ket{\psi} are said to be equal quantum states except for the global phase θ\theta.

For example, 0\ket{0} and 0-\ket{0} are considered equal except for a global phase θ=π\theta = \pi.

Since the global phase does not affect the measurement results of the quantum state, quantum states with different global phases are judged to be equivalent in QCoder.