# Q&A

Last updated: June 27th, 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:

- Basics of quantum information - IBM Quantum Learning:

Official Qiskit tutorials on quantum computing. - Quantum Native Dojo:

A Jupyter Notebook-based resource covering a wide range of topics from the basics to advanced applications of quantum computing.

### 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`

)

- math (
**Qiskit**- QuantumCircuit (
`from qiskit import QuantumCircuit`

) - QuantumRegister (
`from qiskit import QuantumRegister`

)

- QuantumCircuit (
**qiskit.circuit.library**- Any class from this module can be imported. Examples of importable classes include:
- HGate (
`from qiskit.circuit.library import HGate`

) - CXGate (
`from qiskit.circuit.library import CXGate`

) - MCPhaseGate (
`from qiskit.circuit.library import MCPhaseGate`

)

- HGate (

- Any class from this module can be imported. Examples of importable classes include:
**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

### 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 $\ket{0}$ and $\ket{1}$ with coefficients $a_0$ and $a_1$ as follows:

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

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

Since one of the states will always be observed upon measurement, the complex amplitudes $a_0$ and $a_1$ satisfy the normalization condition $|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 $\ket{0}$ and $\ket{1}$ as vectors like:

$\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:

$\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 $n$ qubits can be expressed as a superposition of $2^n$ states as follows:

$\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 $|a_0|^2 + |a_1|^2 + \dots + |a_{2^n-1}|^2 = 1$ holds.

For example, the quantum states of 2 qubits include $\ket{00}$, $\frac{1}{\sqrt{2}} (\ket{00} + \ket{11})$, or $\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 $\ket{b_0b_1...b_{n-1}}$, where $b_i=0,1$. Examples of computational basis states are: $\ket{0}$, $\ket{10}$ or $\ket{111}$.

For example, the quantum state of 2 qubits

$\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 $\ket{00}$, $\ket{10}$, $\ket{01}$, and $\ket{11}$.

Computational basis states can also be represented using decimal notation instead of binary notation, as in $\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 "$X$ gate" inverts the computational basis state of a qubit.

$\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 $X$ 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 $O$ 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 $f$ with input and output as computational basis states, the oracle $O$ can be defined as follows:

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

Note that when applying the oracle, the function $f$ 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.

(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 $\ket{\psi(\theta)} = e^{i\theta}\ket{\psi}$ obtained by multiplying it by $e^{i\theta} = \cos(\theta) + i\sin(\theta)$, where $i$ is the imaginary unit and $\theta$ is some real number.

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

For example, $\ket{0}$ and $-\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.