File size: 5,557 Bytes
db32cff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Render the fields, errors, learning curves, and audited reproduction report."""
import json

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np

from common import config_args, path, read_config


def main():
    args = config_args(__doc__).parse_args()
    cfg = read_config(args.config)
    results = path(cfg['results'])
    metrics = json.loads((results/'metrics.json').read_text())
    with np.load(results/'predictions.npz') as data:
        assert data['prediction'].shape == data['target'].shape == (200,85,85)
        fig, axs = plt.subplots(4,4,figsize=(14,12),constrained_layout=True)
        for i in range(4):
            gt, pred = data['target'][i], data['prediction'][i]
            fields = [data['coeff'][i], gt, pred, np.abs(pred-gt)]
            for j, (field, title) in enumerate(zip(fields,['Permeability','True pressure','Predicted pressure','Absolute error'])):
                kw = dict(vmin=min(gt.min(),pred.min()),vmax=max(gt.max(),pred.max())) if j in [1,2] else {}
                im=axs[i,j].imshow(field,origin='lower',extent=(0,1,0,1),cmap='magma' if j==3 else 'viridis',**kw)
                axs[i,j].set_title(f'Sample {i}: {title}')
                axs[i,j].set_xlabel('x'); axs[i,j].set_ylabel('y')
                fig.colorbar(im,ax=axs[i,j],shrink=.8)
        fig.savefig(results/'pressure_fields.png',dpi=180,bbox_inches='tight')
        plt.close(fig)
        fig,ax=plt.subplots(figsize=(7,4),constrained_layout=True)
        ax.hist(data['relative_l2'],bins=25,color='#286ba5')
        ax.axvline(metrics['mean_relative_l2_raw'],label='Reproduction mean',color='#d44b28')
        ax.axvline(.0070,label='Paper Table 3',color='black',linestyle='--')
        ax.set(xlabel='Raw-scale relative L2 per test sample',ylabel='Count')
        ax.legend(); fig.savefig(results/'test_error_distribution.png',dpi=180,bbox_inches='tight'); plt.close(fig)
    h=np.genfromtxt(results/'history.csv',delimiter=',',names=True)
    assert len(h)==500 and np.array_equal(h['epoch'],np.arange(1,501))
    fig,axs=plt.subplots(1,2,figsize=(11,4),constrained_layout=True)
    axs[0].semilogy(h['epoch'],h['train_relative_l2'],label='Training')
    axs[0].semilogy(h['epoch'],h['test_relative_l2'],label='Test monitoring')
    axs[0].axhline(.007,linestyle='--',color='black',label='Paper Table 3')
    axs[0].set(xlabel='Epoch',ylabel='Raw-scale relative L2'); axs[0].legend()
    axs[1].plot(h['epoch'],h['learning_rate']); axs[1].set(xlabel='Epoch',ylabel='Learning rate')
    fig.savefig(results/'learning_curves.png',dpi=180,bbox_inches='tight'); plt.close(fig)
    limitations='\n'.join('- '+x for x in metrics['limitations'])
    report=f'''# MoNo-light Darcy 85×85 reproduction

Paper: https://arxiv.org/pdf/2608.09764v1, Table 3 and Appendix F.

## Measured result

- Raw-scale per-sample relative L2 mean over all 200 test samples: **{metrics['mean_relative_l2_raw']:.10f}**.
- Paper Table 3: 0.0070; signed difference: **{metrics['signed_gap']:+.10f}**; absolute difference: {metrics['absolute_gap']:.10f}; relative difference: {metrics['relative_gap_percent']:+.4f}%.
- Actual completed training: **500 epochs / 125000 optimizer updates**, batch size 4, max LR .001, 100 warmup epochs.
- Training elapsed time: {float(h['elapsed_seconds'][-1])/3600:.4f} hours.
- Weight choice: **final epoch 500**, saved as `weight/best_model.pth`. Test metrics never select or tune weights. No validation split or early stopping.
- Checkpoint SHA256: `{metrics['checkpoint_sha256']}`.
- Parameters: {metrics['training_environment']['trainable_parameters']:,} trainable; {metrics['training_environment']['all_parameters']:,} including the frozen anchor copy (about 1.73M total).
- Actual package versions: `{metrics['software_versions']}`. Slurm resources: `{metrics['configured_cluster']}`.

## Data and metric

Reuse supplied `piececonst_r421_N1024_smooth1.mat[0:1000]` and `piececonst_r421_N1024_smooth2.mat[0:200]`, fields coeff/sol. Slice `[:,::5,::5]` to 85×85. Global per-channel unbiased train statistics only; reuse for test. Normalize input coordinates/coeff and pressure; inverse-transform pressure before loss and evaluation. Metric is arithmetic mean of each sample's norm(pred-target)/norm(target), recomputed independently with float64 NumPy after checkpoint reload.

## Alignment and limitations

{limitations}

Implementation sources and paper-versus-supplement distinction are preserved in `.trainer_work/darcy85/source_capture.md`. Official code was consulted read-only for paper-unstated details, including a resume audit; no repository downloaded, cloned, copied, or imported. This session reused the saved paper and training specifications.

## Artifacts

- `predictions.npz`: all 200 raw-scale predictions, targets, permeability, coordinates and errors.
- `per_sample_relative_l2.csv`, `metrics.json`, `history.csv`, `data_manifest.json`, `training_environment.json`.
- `pressure_fields.png`: fixed test samples 0--3, common pressure color scale within each sample.
- `test_error_distribution.png`, `learning_curves.png`.
- Runtime stdout/stderr and Slurm evidence: `../logs/` and `../.onescience/`.
'''
    report_path=results/'reproduction_report.md'
    if report_path.exists():
        previous=report_path.read_text()
        if '## Execution provenance' in previous:
            report+='\n## Execution provenance'+previous.split('## Execution provenance',1)[1]
    report_path.write_text(report)
    print(report,flush=True)


if __name__ == '__main__':
    main()