Forge Fate
Quant & Data Research

Checking Synthetic Experiment Replays: What Should Match and What Should Change

3 min read

Rerunning the same inputs does not mean every file must be identical. Run IDs and timestamps may change. Differences in inputs, settings, or calculated results, however, need an explanation.

The recorder in the previous article saves successes and failures in separate directories. This article explains how those directories are compared. It covers the synthetic quant-records-v1 example published on October 7, not a reconstruction of private September runs or a test of actual ETF performance.

Creating runs differs from checking saved records

After completing the installation procedure, run these commands from the package directory. The directory replay-study must not already exist.

sh
python3 experiment.py demo --out replay-studypython3 experiment.py verify --out replay-studypython3 experiment.py verify --out reference-runs

The first command creates baseline success and failure runs plus their replays. The second checks those four newly saved runs. The third checks the October 7 reference records included in the ZIP.

demo replays saved inputs and settings within the same process. It does not rebuild an operating system or environment. verify does not merely read an old PASS flag: it compares files, expected values, and metadata again.

Three kinds of equality

CategoryObjectsExpected relationship
Same calculationInputs, settings, successful result, reportFile presence and bytes match between baseline and replay
New executionRun IDs and directoriesDistinct IDs and directories
Metadata that may changeStart and finish timesExcluded from whole-file byte comparison

Because record.json includes IDs and timestamps, the checker does not require its entire contents to match byte for byte. It compares fields expected to remain stable within the run pair: code, input, and configuration hashes; example and Python versions; status and errors. A reader's new runs under another Python version do not have to contain the same values as the public reference records.

Reports omit run IDs and timestamps. That is this example's design choice to allow direct comparison of reports from identical inputs. A real system that needs timestamps in reports should define a comparison rule that excludes them.

The nine checks behind PASS

The checks section of the verification record contains:

CheckQuestion
success_expected_resultDo both successful results match the public expected result?
failure_expected_recordDo both failures match the expected status, error type, and reason?
failure_result_absentAre result files absent from failed-run directories?
distinct_run_directoriesAre all four runs in distinct directories?
matching_stable_file_bytesDo inputs, settings, results, and reports match in presence and bytes?
matching_fixed_metadataDo fixed fields match, and do hashes agree with files?
new_run_idsDo IDs match directory names, with new IDs for replays?
baseline_files_unchangedDo baseline directories match the snapshot taken immediately before replay?
report_matches_expectedDo reports match the public expected reports?

Matching the baseline and replay alone is insufficient: both could be wrong in the same way. The checker also compares public expected values. For failures, it checks failure status, error details, and absence of a result file, rather than agreement on a result value.

Check that changes are detected

This exercise copies the output directory into a temporary directory, preserving the original. It changes only the copy's successful result and checks that verification fails. Run this Python code from the package directory after creating replay-study above.

python
import jsonimport shutilimport subprocessimport sysimport tempfilefrom pathlib import Pathwith tempfile.TemporaryDirectory() as temporary:    copied = Path(temporary) / 'changed-run'    shutil.copytree('replay-study', copied)    manifest = json.loads((copied / 'verification.json').read_text())    run_id = manifest['runs']['baseline_success']    result_path = copied / run_id / 'result.json'    result = json.loads(result_path.read_text())    result['weights']['SYN_A'] = 0.4    result_path.write_text(json.dumps(result), encoding='utf-8')    completed = subprocess.run(        [sys.executable, 'experiment.py', 'verify', '--out', str(copied)],        capture_output=True, text=True,    )    print('returncode:', completed.returncode)    print(completed.stderr.strip())    if completed.returncode == 0:        raise RuntimeError('변경된 결과를 탐지하지 못했습니다')

This change should break the expected-success-result check, baseline/replay file matching, and baseline-file immutability. A failure code rather than the normal exit code 0 is the expected behavior here. It demonstrates why the checker must reread files even if all previously saved checks were true.

The implementation is in checks and verify in experiment.py. It uses explicit exceptions, so these runtime checks do not disappear under Python optimization flags.

What these checks do not guarantee

Identical files do not establish that the inputs accurately describe reality. These checks do not prevent changing files and hashes together. baseline_files_unchanged compares against a previously saved snapshot stored alongside the records; it is not independent external proof.

The published records cover execution on the same Mac. Reproduction on another operating system, environment locking, recovery from disk errors or forced termination, and actual ETF predictive ability are outside the scope. Environments and boundaries are documented in validation.json.

The useful outcome of this recording exercise is more specific than the word “reproduced”: which inputs, which environment, which files and fields were compared, and what was not compared? Actual ETF comparison results are available in the separate baseline execution article.

Report an error or share feedback

Open a draft with this article’s title and URL. Review the message and recipient before sending.

To: [email protected]

Open email draft

If no email app opens, copy these details into your usual email service.

Contact information