Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion TASK_DETAILS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ We welcome new engineering problem ideas — even without complete verification
<td>Cross-modality gene expression prediction (RNA → ADT), NeurIPS 2021</td>
</tr>
<tr>
<td rowspan="3"><b>QuantumComputing</b></td>
<td rowspan="4"><b>QuantumComputing</b></td>
<td><code>routing_qftentangled</code></td>
<td>QFT circuit routing optimization on IBM Falcon (gate count &amp; depth)</td>
</tr>
Expand All @@ -68,6 +68,10 @@ We welcome new engineering problem ideas — even without complete verification
<td><code>cross_target_qaoa</code></td>
<td>Cross-target robust QAOA optimization for IBM and IonQ backends</td>
</tr>
<tr>
<td><code>KernelBlockEncoding</code></td>
<td>Normalization-aware FABLE circuit construction for QML kernel matrices under independent resource and block-error evaluation</td>
</tr>
<tr>
<td rowspan="3"><b>Cryptographic</b></td>
<td><code>AES-128 CTR</code></td>
Expand Down
6 changes: 5 additions & 1 deletion TASK_DETAILS_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Frontier-Eng 目前已覆盖以下领域的任务。每个任务均配有可运
<td>跨模态基因表达预测(RNA → ADT),NeurIPS 2021</td>
</tr>
<tr>
<td rowspan="3"><b>QuantumComputing</b></td>
<td rowspan="4"><b>QuantumComputing</b></td>
<td><code>routing_qftentangled</code></td>
<td>QFT 线路路由优化,IBM Falcon(gate count &amp; depth)</td>
</tr>
Expand All @@ -68,6 +68,10 @@ Frontier-Eng 目前已覆盖以下领域的任务。每个任务均配有可运
<td><code>cross_target_qaoa</code></td>
<td>跨目标鲁棒 QAOA 优化(IBM &amp; IonQ)</td>
</tr>
<tr>
<td><code>KernelBlockEncoding</code></td>
<td>在独立资源与分块误差评测下,为 QML 核矩阵构造归一化感知的 FABLE 电路</td>
</tr>
<tr>
<td rowspan="3"><b>Cryptographic</b></td>
<td><code>AES-128 CTR</code></td>
Expand Down
68 changes: 68 additions & 0 deletions benchmarks/QuantumComputing/KernelBlockEncoding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Kernel Block Encoding

This benchmark asks a C++ policy to construct compressed FABLE-style quantum
circuits for fixed-point kernel and Gram matrices used in machine learning. A
candidate chooses a partial-Hadamard basis, normalization, and sparse quantized
rotation vector. The independent evaluator analytically reconstructs the encoded
matrix, enforces the approximation budget, and applies a frozen gate compiler and
resource objective.

This is a circuit-construction task, not QML training or state-vector simulation.
The candidate directly changes the block encoding that is measured.

## Files

- `Task.md`: mathematical contract, C++ API, resource model, workloads, and score.
- `references/problem_config.json`: frozen kernels, limits, and objective weights.
- `references/README.md`: research and construction references.
- `scripts/init.cpp`: editable C++17 starter policy.
- `verification/construction_runtime.hpp`: immutable candidate-side construction API.
- `verification/evaluator.py`: independent workload generator, certificate checker,
analytic block reconstruction, frozen resource compiler, and scorer.
- `verification/limited_exec.py`: thread-safe POSIX hard-limit launcher for candidate
processes.
- `baseline/solution.cpp`: frozen starter used for score normalization.
- `baseline/result_log.txt`: measured reference evaluation.
- `frontier_eval/`: unified-task metadata and evaluator wrapper.

## Requirements

- Linux or another POSIX environment with Python 3.10+;
- `g++` with C++17 support; and
- one CPU core with less than 1 GiB RAM.

There are no Python packages, downloads, containers, external solvers, GPUs,
Qiskit, or quantum simulators.

The complete frozen-starter evaluation takes about 2.8 seconds on the repository's
current AMD EPYC host, including two C++ compilations and twelve construction runs.

## Direct evaluation

From this task directory:

```bash
python verification/evaluator.py scripts/init.cpp \
--metrics-out metrics.json --artifacts-out artifacts.json
```

The unmodified starter reports `valid=1.0` and `combined_score=1.0`. A score above
1.0 is an improvement over the frozen starter.

## Unified evaluation

From the repository root:

```bash
.venvs/frontier-eval-driver/bin/python -m frontier_eval \
task=unified \
task.benchmark=QuantumComputing/KernelBlockEncoding \
algorithm=openevolve \
algorithm.iterations=0
```

## Editing contract

Only change code between `EVOLVE-BLOCK-START` and `EVOLVE-BLOCK-END` in
`scripts/init.cpp`. The evaluator byte-compares the immutable source prefix and
suffix against the frozen baseline before compiling a candidate.
214 changes: 214 additions & 0 deletions benchmarks/QuantumComputing/KernelBlockEncoding/Task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
# Task: Kernel Block Encoding

## 1. Engineering problem

Many quantum linear-algebra and quantum machine-learning algorithms assume access
to a unitary whose leading block is a scaled approximation of a classical matrix.
General constructions exist, but the actual circuit can be dominated by data
loading, normalization, controlled rotations, and routing. Kernel matrices make
the issue concrete: they are dense, but their geometry can create exploitable
structure in a suitable basis.

This task exposes construction co-design directly. Given a real symmetric kernel
matrix, choose:

- a computational or partial-Hadamard basis;
- the block-encoding normalization;
- which uniformly controlled rotations to retain; and
- the value of every retained, quantized rotation.

The output is a concrete compressed FABLE construction. The evaluator does not run
a QML model and does not estimate quality from a state-vector sample. It
reconstructs the encoded block from the construction integers and computes the
resources of the corresponding frozen gate schedule.

## 2. Block-encoding family

Let `N = 2^n` and let `A` be an `N x N` fixed-point input matrix. A candidate first
selects an `n`-bit `basis_mask`. If bit `k` is set, a normalized Hadamard is applied
to qubit `k` on both sides of the matrix:

```text
B = H_mask A H_mask
```

The evaluator implements this transform with integer butterflies. Applying a
Hadamard on both matrix axes contributes an exact denominator of two, so no
floating-point matrix transform is needed.

The candidate then selects `s >= max_ij |B_ij|`. Define

```text
C_ij = B_ij / s
theta_ij = 2 arccos(C_ij)
```

Flatten `theta` in row-major order. With `W` the unnormalized Walsh-Hadamard matrix
of order `N^2` and `P_G` the binary-reflected Gray permutation, the uniformly
controlled rotation coefficients are

```text
hat_theta = P_G (W / N^2) theta.
```

Every emitted coefficient is an integer number of
`pi / 268435456` radians. Omitted coefficients are exactly zero. The checker
inverts the Gray permutation and Walsh-Hadamard transform and obtains

```text
B_tilde_ij = s cos(theta_tilde_ij / 2).
```

The FABLE oracle, diffusion layers, row/system swap, and optional basis wrappers
therefore form a unitary `U` on `2n + 1` qubits whose leading block is
`A_tilde / (N s)`. Its normalization is

```text
alpha = N s.
```

The construction uses `n + 1` block-encoding ancillas and `n` system qubits.

## 3. Validity condition

For the system-register leading block of `U`, every workload requires

```text
|| A - alpha (<0^(n+1)| tensor I) U (|0^(n+1)> tensor I) ||_F <= epsilon.
```

The evaluator reconstructs the left-hand matrix directly. Since the spectral norm
is no greater than the Frobenius norm, every accepted construction also has
spectral block error at most `epsilon`.

Targets, basis transforms, scale bounds, Gray permutations, and quantized angle
transforms are independently recomputed in Python. Candidate-reported errors and
resource counts are ignored. A small explicit floating-point guard is added to the
computed trigonometric error before the validity comparison.

## 4. Candidate API

Only this function is editable:

```cpp
void optimize(kernel_block_encoding::Construction& construction);
```

The immutable class in `verification/construction_runtime.hpp` provides:

```cpp
std::size_t dimension() const;
std::size_t system_qubits() const;
std::size_t coefficient_count() const;
long double epsilon() const;
long double target(std::size_t row, std::size_t column) const;

void set_basis_mask(std::uint32_t mask);
std::int64_t minimum_scale_numerator() const;
void set_scale_numerator(std::int64_t numerator);
void set_scale_multiplier(long double multiplier);

std::vector<std::int64_t> exact_angle_ticks() const;
long double frobenius_error(const std::vector<std::int64_t>& ticks) const;
ResourceEstimate resources(const std::vector<std::int64_t>& ticks) const;
long double objective(const std::vector<std::int64_t>& ticks) const;
void commit(std::vector<std::int64_t> ticks);
```

Changing the basis resets the minimum scale. The scale numerator may range from the
new minimum through 16 times that minimum. `exact_angle_ticks()` produces the full
quantized FABLE vector for the current basis and scale; a policy may drop or alter
any tick before committing it. Helper error and resource methods support search,
but only the independent Python reconstruction determines the score.

## 5. Frozen circuit resources

The sparse coefficient vector is compiled with the compressed uniform-rotation
schedule:

1. traverse control states in binary-reflected Gray order;
2. emit one `RY` for each nonzero coefficient;
3. across a run of zero rotations, cancel repeated control toggles and emit one
CNOT for each bit with odd transition parity;
4. close the Gray cycle;
5. add the two `n`-Hadamard diffusion layers and `n` register swaps; and
6. add two Hadamards for every selected basis qubit.

The reported counts are:

- arbitrary-angle `RY` rotations;
- oracle and total CNOTs, with each SWAP decomposed into three CNOTs;
- Hadamards;
- logical depth of the frozen schedule; and
- `2n + 1` logical qubits.

All oracle rotations and CNOTs touch the rotation target, so they are sequential in
this construction. The register swaps are disjoint and contribute three depth
layers.

## 6. Workloads

The evaluator deterministically generates six fixed-point matrices:

1. a 16-sample clustered anisotropic RBF kernel;
2. a 32-sample, higher-dimensional clustered RBF kernel;
3. a 32-sample degree-three polynomial Gram matrix;
4. a 32-sample rational-quadratic kernel;
5. a 32-node random-walk feature Gram matrix; and
6. a 64-sample mixture of two RBF length scales.

The RBF generators use high-precision decimal exponentiation before fixed-point
rounding. Polynomial, rational, and walk kernels use integer arithmetic. Input
bytes and SHA-256 digests are frozen in `references/problem_config.json` and
reported in `artifacts.json`.

## 7. Objective

For a valid construction, the frozen compiled cost is

```text
16 * RY + 1 * CNOT + 0.25 * H + 0.25 * depth.
```

The scenario objective is

```text
effective_cost = alpha * compiled_cost.
```

Multiplying by `alpha` makes normalization part of the optimization: a basis that
compresses strongly can still lose if its transformed maximum entry is large.

For scenario `i`:

```text
score_i = baseline_effective_cost_i / candidate_effective_cost_i.
```

`combined_score` is the geometric mean across all six scenarios. The direct-basis,
global-threshold starter is frozen as the baseline and scores exactly 1.0. Larger
is better.

The evaluator isolates workload failures and continues through the full suite. A
failed workload retains its baseline data and a workload-level error, while every
successful workload retains its independently checked score. `partial_combined_score`
is the geometric mean over those successful workloads and is diagnostic only. The
official `combined_score` remains zero and `valid=0.0` unless all six workloads
succeed, so skipping a difficult scenario can never improve the optimization
target.

## 8. Limits and reproducibility

- matrix dimensions are at most 64;
- scale is at most 16 times the basis-dependent minimum;
- angle certificates are at most 256 KiB;
- candidate source is at most 1 MB;
- candidate execution is limited to 5 seconds and 1 GiB per workload;
- candidate processes are subject to `RLIMIT_NPROC=64` where supported; and
- compilation uses `g++ -std=c++17 -O2`.

There is no network access, external solver, quantum SDK, simulator, container,
GPU, or downloaded data. Compilation is outside candidate execution time but is
included in evaluator wall time. Invalid source edits, malformed certificates,
timeouts, scale violations, or excessive block error produce `valid=0.0` and score
0.0.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
KernelBlockEncoding frozen starter reference
============================================

Command:
python verification/evaluator.py scripts/init.cpp \
--metrics-out metrics.json --artifacts-out artifacts.json

Environment:
Linux 5.15 x86_64
Python 3.10.12
g++ 11.4.0
AMD EPYC 7313 host

Summary:
valid=1.0
combined_score=1.0
partial_combined_score=1.0
scenario_count=6
successful_scenario_count=6
failed_scenario_count=0
checked_matrix_entries=8448
total_rotations=6936
total_cnots=7788
evaluator_wall_s=2.748

Per workload (epsilon, error upper bound, alpha, RY, oracle CNOT, objective):
clustered_rbf_16 0.1055240631 0.0433050655 16 236 256 66724
anisotropic_rbf_32 0.0925254822 0.0662628832 32 896 1016 507160
polynomial_gram_32 0.0619373322 0.0455802581 32 946 1020 533320
rational_quadratic_32 0.1412220001 0.1033587668 32 930 1018 524920
walk_feature_gram_32 0.1810274124 0.0784774292 32 144 292 87160
multiscale_rbf_64 0.1095294952 0.0768379219 64 3784 4096 4264464

Times are descriptive rather than scored. The score uses only independently
reconstructed block error, normalization, and frozen logical circuit resources.
Loading
Loading