FP64 state-vector simulation of a seeded 27-qubit random circuit
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
A dense state-vector simulation of one seeded random quantum circuit on n qubits, in FP64
complex arithmetic. The state holds 2^n amplitudes; bit q of an amplitude index is qubit q.
-
Initial state. Amplitude
jisu(2j) + i*u(2j+1)withu(t) = (mix64(seed ^ (t * 0xA24BAED4963EE407)) >> 11) * 2^-52 - 1(a dense pseudo-random vector,mix64= SplitMix64 finaliser), then the whole vector is normalised to unit norm. -
Circuit.
Ggates are built on the host by a sequential SplitMix64-style generator seeded fromseed(cheap; the CPU source is the exact specification). Every 6-14 gates a new "focus set" of 7 qubits is drawn and 80% of the following gates act inside it. Gate kinds:u1: a random single-qubit unitarye^{ig} Rz(a) Ry(b) Rz(d);kak: a random two-qubit gate(A0 x A1) * exp(i(a XX + b YY + c ZZ)) * (B0 x B1)with four random single-qubit unitaries;fsim:fSim(theta, phi);ctrl: a controlled random single-qubit unitary (controlq[0], targetq[1]);diag3: a diagonal three-qubit gate with 8 random phases.
A two-qubit gate on
(q0, q1)is a dense 4x4 matrix acting on the local indexk = b0 + 2*b1whereb0,b1are the bitsq0,q1of the amplitude index;diag3usesk = b0 + 2*b1 + 4*b2. Whennis too small for a gate kind (n < 2orn < 3) the generator uses au1gate instead. Gates are applied in order. -
Observables of the final state
a, withp_j = |a_j|^2:norm = sum p_jandcollision = 2^n * sum p_j^2;<Z_q> = sum p_j (1 - 2*bit_q(j))for every qubit;<Z_a Z_b>for 16 seeded qubit pairs (only whenn >= 2);- 16 sampled amplitudes
a_idx * 2^(n/2)and 1024 sampled probabilitiesp_idx * 2^nat seeded indices (indices may repeat).
The CPU program applies each gate as one parallel pass over the state and reduces the observables over fixed chunks, so its output does not depend on the thread count.
Input format
One line: n G SEED (SEED is an unsigned 64-bit integer).
Output format
qubits n gates G
counts u1=.. kak=.. fsim=.. ctrl=.. diag3=..
norm X
collision X
z X X ... (<Z_q> for q = 0..n-1, at most 9 per line)
zz A B X (16 lines when n >= 2)
amp IDX RE IM (16 lines)
p X X ... X (64 lines of 16 scaled probabilities)
Floating-point values are printed with %.12e. They are compared with a relative tolerance of
1e-8 plus an absolute tolerance of 1e-9; integer tokens and words must match exactly. FP64
amplitudes are required: any fusion, reordering or blocking of the gate arithmetic is fine, but
FP32 state storage will not meet the tolerance.
Hidden inputs
1 <= n <= 27, 0 <= G <= 700. Correctness inputs include n = 1, 2, 3 (gate-kind fallbacks),
G = 0, G = 640 on tiny registers, and registers up to n = 22. The timing input has
n = 27 (a 2 GiB state) and G in [300, 340].
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass.
Your output must have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-08 and atol = 1e-09; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has n = 27 qubits (2 GiB of FP64 complex amplitudes) and 300 to 340 gates. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.