Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4a14fad
Add magnetohydrodynamics cpp-hlld benchmark scaffold
amanotk Mar 7, 2026
9d80fb7
Fix GitHub math rendering in HLLD doc
amanotk Mar 7, 2026
b5be13f
Strengthen cpp-hlld benchmark guidance and tests
amanotk Mar 8, 2026
bf251b9
Update formatting of starred-state update equations
amanotk Mar 8, 2026
b2e6ab5
Merge develop into feature/magnetohydrodynamics
amanotk Mar 28, 2026
6215af3
Fix hidden test merge artifact
amanotk Mar 28, 2026
7c982ca
Strengthen HLLD coverage and fix Docker OpenCode setup
amanotk Mar 28, 2026
1388e34
Add full 1D MHD benchmark with Brio-Wu reference
amanotk Mar 28, 2026
777ac30
Add golden Brio-Wu CLI regression test
amanotk Mar 28, 2026
b3841c2
Refactor MHD state storage to mdspan views
amanotk Mar 28, 2026
595afcf
checkpoint: spiral-unknown-1774769904852
amanotk Mar 29, 2026
c8e08d6
checkpoint: spiral-unknown-1774773137200
amanotk Mar 29, 2026
a67994d
Migrate cpp-full-solver1d to mdspan views
amanotk Mar 29, 2026
5290c7c
Refactor Brio-Wu CLI around SolverWorkspace
amanotk Mar 29, 2026
37eb42e
WIP: normalize solver workspace shapes
amanotk Mar 29, 2026
a719ec4
WIP: add primitive reconstruction helper
amanotk Mar 29, 2026
3f6d4a9
WIP: add workspace-patterned RK3 path
amanotk Mar 31, 2026
80acf96
WIP: run full solver via workspace-patterned RK3
amanotk Mar 31, 2026
c2eddde
Migrate fully to workspace-patterned RK3 solver
amanotk Mar 31, 2026
a88dc8d
checkpoint: spiral-unknown-1775016836330
amanotk Apr 1, 2026
98e4bf2
checkpoint: spiral-unknown-1775016843861
amanotk Apr 1, 2026
fa65f36
checkpoint: spiral-unknown-1775016849781
amanotk Apr 1, 2026
b70f67b
refactor(cpp-full-solver1d): simplify API and remove dead code
amanotk Apr 1, 2026
a6e4cb8
refactor(cpp-full-solver1d): drop dt/t_final from SolverWorkspace
amanotk Apr 1, 2026
32138c3
refactor(cpp-full-solver1d): clean up initialize and cell center inde…
amanotk Apr 1, 2026
98f26be
refactor(cpp-full-solver1d): simplify storage and boundary handling
amanotk Apr 1, 2026
1d410df
refactor(cpp-full-solver1d): tighten workspace layout and boundaries
amanotk Apr 1, 2026
2f5e503
refactor(magnetohydrodynamics): reduce grid resolution from 400 to 10…
amanotk Apr 1, 2026
c782f7b
refactor(magnetohydrodynamics): move reference code into shared assets
amanotk Apr 1, 2026
9794436
chore(magnetohydrodynamics): remove obsolete fixture json
amanotk Apr 1, 2026
ddad41e
refactor(magnetohydrodynamics): streamline shared solver interfaces
amanotk Apr 2, 2026
60e6af7
refactor(magnetohydrodynamics): split cpp-hlld into 00/01 variants
amanotk Apr 2, 2026
788cc05
chore: add vscode workspace excludes
amanotk Apr 2, 2026
6aac2fe
chore: add uv lockfile
amanotk Apr 2, 2026
e2171fc
refactor(magnetohydrodynamics): replace full-solver task with cpp-ful…
amanotk Apr 2, 2026
db0bf44
feat(magnetohydrodynamics): add cpp-full1d-01 variant with minimal API
amanotk Apr 2, 2026
0f29b13
fix(magnetohydrodynamics): use absolute paths in hidden eval tests
amanotk Apr 2, 2026
f0a3353
fix(magnetohydrodynamics): fix WORKSPACE_ROOT path to /work
amanotk Apr 2, 2026
70f3fa1
Simplify MHD test build dir and code style
amanotk Apr 2, 2026
0c12fdd
fix(mhd): correct HLLD flux loop bound to prevent buffer overflow
amanotk Apr 2, 2026
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
1 change: 1 addition & 0 deletions .github/workflows/toolchain-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
FLAP_VERSION=1.2.16
OPENCODE_VERSION=1.3.3
CATCH2_REF=v3.13.0
MDSPAN_REF=mdspan-0.6.0
XTL_REF=0.8.2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ __pycache__/
.venv/
venv/
.DS_Store
benchmarks/*/*/workspace/build/
benchmarks/*/*/workspace/build-review/
35 changes: 35 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"files.exclude": {
"**/.git/objects/**": true,
"**/.git/refs/**": true,
"**/.pytest_cache/**": true,
"**/__pycache__": true,
"**/.ruff_cache/**": true,
"**/.venv/**": true,
"**/.opencode-data/**": true
},
"files.watcherExclude": {
"**/runs/**": true,
"**/.git/objects/**": true,
"**/.git/refs/**": true,
"**/.ruff_cache/**": true,
"**/.venv/**": true,
"**/.opencode-data/**": true,
"**/node_modules/**": true,
"**/__pycache__/**": true,
"**/build/**": true
},
"search.exclude": {
"**/runs/**": true,
"**/.git/**": true,
"**/.ruff_cache/**": true,
"**/.venv/**": true,
"**/.opencode-data/**": true,
"**/node_modules/**": true,
"**/__pycache__/**": true
},
"C_Cpp.files.exclude": {
"**/build/**": true,
"**/runs/**": true
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Configured in `agents_default.toml` (with per-agent overrides under `sample/*.to
## Available Benchmarks
- Demo benchmark for Runge-Kutta 2 (RK2) midpoint method.
- 3D wave equation solver with finite difference method.
- Magnetohydrodynamics (MHD) solver.

## Quick Start

Expand Down
4 changes: 3 additions & 1 deletion agents_default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ pass_env = [
]
pre = [
"mkdir -p \"$HOME/.local/share/opencode\"",
"mkdir -p \"$HOME/.config/opencode\"",
"if [ -f /opencode-auth.json ]; then cp /opencode-auth.json \"$HOME/.local/share/opencode/auth.json\"; fi",
"if [ -f /opencode-config.json ]; then export OPENCODE_CONFIG=/opencode-config.json; elif [ -f /opencode-config.jsonc ]; then export OPENCODE_CONFIG=/opencode-config.jsonc; fi",
"if [ -f /opencode-config.json ]; then cp /opencode-config.json \"$HOME/.config/opencode/opencode.json\"; fi",
"if [ -f /opencode-config.jsonc ]; then cp /opencode-config.jsonc \"$HOME/.config/opencode/opencode.jsonc\"; fi",
]
cmd = "stdbuf -oL -eL opencode run -m \"$BENCH_MODEL\" $BENCH_MODEL_OPTIONS_ARGS --thinking --dir / \"$(cat \"$BENCH_PROMPT_FILE\")\" -f \"$BENCH_SPEC_FILE\""

Expand Down
18 changes: 17 additions & 1 deletion benchmarks/magnetohydrodynamics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,29 @@ This suite contains benchmark tasks for ideal magnetohydrodynamics solvers.

- `shared/workspace/basic_equations.md`: suite-wide notation and flux conventions.
- `shared/workspace/hlld.md`: HLLD algorithm notes for solver tasks.
- `cpp-hlld/`: C++ HLLD approximate Riemann solver task.
- `cpp-hlld-00/`: default C++ HLLD task with detailed solver guidance in spec.
- `cpp-hlld-01/`: variant C++ HLLD task with reduced guidance but same test intent.
- `cpp-full1d-00/`: easiest C++ full 1D ideal MHD variant (main+HLLD provided, solver scaffolded).
- `cpp-full1d-01/`: reduced-guidance full 1D variant with only `evolve_ssp_rk3(...)` exposed.
- `shared/eval/README.md`: hidden-eval contract for shared MHD scoring assets.
- `shared/eval/mhd1d_shared.py`: shared helpers for CSV loading, score
windows, and comparison metadata.
- `shared/eval/fixtures/mhd1d/`: hidden fixtures for full 1D variants.

## Notes

- Shared workspace files are visible to the agent during benchmark runs.
- Keep maintainer-only derivations, generators, and hidden fixtures outside the
shared workspace.
- `cpp-hlld-00` and `cpp-hlld-01` expose only
`hlld_flux_from_primitive(...)` in the public task API.
- `cpp-hlld-00` and `cpp-hlld-01` keep public/hidden test intent aligned;
the main difference is prompt detail level.
- `cpp-full1d-00` public tests compare solver CSV output against a golden file
with numeric tolerance (`1.0e-12`), and hidden tests use `nx=200` against a
hidden reference CSV with the same numeric policy.
- Full 1D tasks score interior cells and emit CSV with lowercase magnetic-field
headers (`by`, `bz`).

## Reference credit

Expand Down
28 changes: 28 additions & 0 deletions benchmarks/magnetohydrodynamics/cpp-full1d-00/eval/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -u -o pipefail

cd /work
export PYTHONPATH="/work:/eval_shared"

status="passed"
score="1.0"

python3 -m pytest -q /eval/tests
rc=$?
if [ "$rc" -ne 0 ]; then
status="failed"
score="0.0"
fi

python3 - <<PY
import json
from pathlib import Path

out = {
"status": "$status",
"score": float("$score"),
}
Path("result.json").write_text(json.dumps(out, indent=2) + "\n", encoding="utf-8")
PY

exit 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import csv
import os
import subprocess
from pathlib import Path

from mhd1d_shared import TOLERANCE, assert_csv_rows_close

SOLVER_TARGET = "cpp_full_solver1d"
WORKSPACE_ROOT = Path("/work")
REFERENCE_CSV_PATH = (
Path("/eval_shared") / "fixtures" / "mhd1d" / "brio_wu_reference.csv"
)


def _build_solver(build_dir: Path) -> Path:
subprocess.run(
["cmake", "-S", ".", "-B", str(build_dir)], check=True, cwd=WORKSPACE_ROOT
)
subprocess.run(
["cmake", "--build", str(build_dir), "--target", SOLVER_TARGET],
check=True,
cwd=WORKSPACE_ROOT,
)

binary_name = f"{SOLVER_TARGET}.exe" if os.name == "nt" else SOLVER_TARGET
solver_path = build_dir / "bin" / binary_name
assert solver_path.exists()
return solver_path


def test_hidden_brio_wu_cli_matches_fixture(tmp_path: Path) -> None:
solver_path = _build_solver(tmp_path / "build")
output_csv_path = tmp_path / "brio_wu.csv"

completed = subprocess.run(
[str(solver_path), "200"],
check=True,
capture_output=True,
text=True,
)
output_csv_path.write_text(completed.stdout, encoding="utf-8")

output_rows = list(
csv.reader(output_csv_path.read_text(encoding="utf-8").splitlines())
)
reference_rows = list(
csv.reader(REFERENCE_CSV_PATH.read_text(encoding="utf-8").splitlines())
)

assert_csv_rows_close(
output_rows,
reference_rows,
tolerance=TOLERANCE,
expected_header=["x", "rho", "u", "v", "w", "p", "by", "bz"],
)
74 changes: 74 additions & 0 deletions benchmarks/magnetohydrodynamics/cpp-full1d-00/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# cpp-full1d-00

Implement a 1D ideal-MHD solver CLI in C++.

## Read first

- `/work/basic_equations.md`
- `/work/hlld.md`

## Task

The command-line entrypoint and the HLLD Riemann solver are already provided.
The CLI accepts an integer `nx` argument for the number of grid points, performs the Brio-Wu Riemann problem, and writes the solution to stdout in CSV format.
Your main task is to complete the solver implementation in `src/mhd1d.cpp`.

The CLI output must match the provided golden CSV for `nx=100` within numeric tolerance (`1.0e-12`).

## How to test

Run the public checks from the workspace:

```bash
python3 -m pytest -q tests/test_public.py
```

## Local dev

```bash
pytest -q
```

To build manually:

```bash
cmake -S . -B build
cmake --build build
./build/bin/cpp_full_solver1d
```

## Numerical Algorithm

- Riemann solver: HLLD
- Primitive variables reconstruction: piecewise linear with MC2 slope limiter
- Time integration: SSP-RK3
- Boundary condition: symmetric (zero-gradient)

## Files

- `src/main.cpp`: complete CLI (already done)
- `src/hlld.hpp`, `src/hlld.cpp`: complete HLLD implementation (already done)
- `src/mhd1d.hpp`, `src/mhd1d.cpp`: solver scaffolding to complete

## Functions to complete (in `src/mhd1d.cpp`)

The easiest path is to implement these functions first:

1. `primitive_to_conservative(...)`
2. `conservative_to_primitive(...)`
3. `compute_lr(...)`
4. `compute_rhs(...)`
5. `push_ssp_rk3(...)`
6. `evolve_ssp_rk3(...)`

Recommended implementation order:

1. Reconstruction (`compute_lr`)
2. Flux loop (`compute_flux_hlld` already calls provided HLLD)
3. RHS assembly (`compute_rhs`)
4. One RK3 step (`push_ssp_rk3`)
5. Time loop (`evolve_ssp_rk3`)

## Standards

- C++17
8 changes: 8 additions & 0 deletions benchmarks/magnetohydrodynamics/cpp-full1d-00/task.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
id = "cpp-full1d-00"
suite = "magnetohydrodynamics"
language = "cpp"
time_limit_sec = 600
eval_cmd = "/eval/run.sh"
prompt = "Read /run/spec.md, /work/basic_equations.md, and /work/hlld.md, then solve the task in /work."
use_shared_workspace = true
use_shared_eval = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.16)

project(cpp_full_solver1d LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(FetchContent)

find_package(Catch2 3 QUIET)

if(NOT Catch2_FOUND)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.13.0
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(Catch2)
endif()

add_library(mhd1d_solver
src/mhd1d.cpp
src/hlld.cpp
)

target_include_directories(mhd1d_solver PUBLIC
src
../../../common/include
)

add_executable(cpp_full_solver1d
src/main.cpp
)

target_link_libraries(cpp_full_solver1d PRIVATE
mhd1d_solver
)

set_target_properties(cpp_full_solver1d PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

add_executable(cpp_full_solver1d_public_tests
tests/cpp/test_public.cpp
)

target_link_libraries(cpp_full_solver1d_public_tests PRIVATE
mhd1d_solver
Catch2::Catch2WithMain
)

target_include_directories(cpp_full_solver1d_public_tests PRIVATE
src
../../../common/include
)

set_target_properties(cpp_full_solver1d_public_tests PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The public C++ workspace contains a Brio-Wu solver scaffold.

- `src/main.cpp` is complete.
- `src/hlld.cpp` is complete.
- `src/mhd1d.cpp` contains TODO sections to implement.

Shared workspace docs are already mounted for this benchmark.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[project]
name = "magnetohydrodynamics-cpp-full1d-00"
version = "0.0.0"
requires-python = ">=3.10"

[tool.pytest.ini_options]
testpaths = ["tests"]
Loading
Loading