Download scripts/finalize.py from OneScience-Group/MoNo-light: direct link, hf CLI and curl.
- Browser
- Download file 4.56 kB
-
https://huggingface.co/OneScience-Group/MoNo-light/resolve/main/scripts/finalize.py
- Command line
-
hf download hf://OneScience-Group/MoNo-light/scripts/finalize.py
-
curl -L -o finalize.py https://huggingface.co/OneScience-Group/MoNo-light/resolve/main/scripts/finalize.py
4.56 kB
| """Audit completed artifacts and update OneScience state from real execution evidence.""" | |
| import json | |
| import hashlib | |
| import os | |
| from pathlib import Path | |
| import numpy as np | |
| from common import ROOT, atomic_json | |
| def main(): | |
| results=ROOT/'results' | |
| metrics=json.loads((results/'metrics.json').read_text()) | |
| for filename,digest in metrics['training_environment']['code_hashes'].items(): | |
| assert hashlib.sha256((ROOT/filename).read_bytes()).hexdigest()==digest, filename | |
| history=np.genfromtxt(results/'history.csv',delimiter=',',names=True) | |
| assert len(history)==500 and history['updates'][-1]==125000 | |
| assert np.array_equal(history['epoch'],np.arange(1,501)) | |
| assert np.array_equal(history['updates'],250*np.arange(1,501)) | |
| assert all(np.isfinite(history[k]).all() for k in history.dtype.names) | |
| with np.load(results/'predictions.npz') as data: | |
| pred,target=data['prediction'],data['target'] | |
| assert pred.shape==target.shape==(200,85,85) | |
| assert np.isfinite(pred).all() and np.isfinite(target).all() | |
| err=np.linalg.norm((pred.astype('float64')-target).reshape(200,-1),axis=1)/np.linalg.norm(target.astype('float64').reshape(200,-1),axis=1) | |
| assert abs(float(err.mean())-metrics['mean_relative_l2_raw'])<1e-12 | |
| np.testing.assert_allclose(float(err.mean()),history['test_relative_l2'][-1],rtol=1e-4,atol=1e-7) | |
| for name in ['pressure_fields.png','test_error_distribution.png','learning_curves.png','reproduction_report.md']: | |
| assert (results/name).stat().st_size>1000 | |
| proof=dict(status='success',job_id=os.environ.get('SLURM_JOB_ID'), | |
| epochs=500,updates=125000,test_samples=200, | |
| mean_relative_l2_raw=metrics['mean_relative_l2_raw'], | |
| signed_gap=metrics['signed_gap'],selection=metrics['selection'], | |
| checkpoint=str(ROOT/'weight/best_model.pth'),report=str(results/'reproduction_report.md')) | |
| report_path=results/'reproduction_report.md' | |
| report=report_path.read_text() | |
| provenance='''\n## Execution provenance\n\nThe prior interrupted session had completed specifications and handoffs but left the model, script, and weight directories empty. This session reused those documents and the original data. Slurm smoke job1100898 passed all six paths. Job1100916 failed at startup before training output or checkpoint creation. The same full-budget experiment continued as job1100920 after excluding that startup-fault node; no formal epochs were discarded or restarted from an existing trained model. See `.onescience/task_state_before_resume.json` and runtime events for the audit trail.\n''' | |
| if '## Execution provenance' not in report: | |
| report_path.write_text(report+provenance) | |
| for directory,skill in [('.trainer_work/darcy85','onescience-trainer'),('.infer_work','onescience-infer')]: | |
| work=ROOT/directory | |
| atomic_json(work/'execution_result.json',dict(skill=skill,status='success',artifacts=proof, | |
| observation={'validation':'passed; results/artifact_audit.json','limitations':metrics['limitations']})) | |
| (work/'validation_report.md').write_text((results/'reproduction_report.md').read_text()) | |
| atomic_json(work/'runtime_result.json',dict(execution_channel='local_slurm',execution_mode='slurm', | |
| preflight_passed=True,submission_state='submitted',execution_state='success', | |
| job_id=os.environ.get('SLURM_JOB_ID'),local_log_dir=str(ROOT/'logs'),blocking_reason=None)) | |
| manifest_path=work/('trainer_run_manifest.json' if skill=='onescience-trainer' else 'inference_run_manifest.json') | |
| manifest=json.loads(manifest_path.read_text()) if manifest_path.exists() else {} | |
| manifest.update(status='success',job_id=os.environ.get('SLURM_JOB_ID'),artifacts=proof) | |
| manifest['phase_status']={k:'success' for k in manifest.get('phase_status',{'execution':'running','validation':'pending'})} | |
| atomic_json(manifest_path,manifest) | |
| state_path=ROOT/'.onescience/task_state.json' | |
| state=json.loads(state_path.read_text()) | |
| state.update(status='completed',current_phase='completed',active_step=None,blockers=[],final_result=proof) | |
| for step in state['global_plan']: | |
| step['status']='success' | |
| state['events'].append(dict(event_type='task_completed',evidence=str(results/'artifact_audit.json'))) | |
| atomic_json(state_path,state) | |
| atomic_json(results/'artifact_audit.json',proof) | |
| print('FINAL_AUDIT',proof,flush=True) | |
| if __name__=='__main__': | |
| main() | |