RheoBench / explore /PhaseLatch /scripts /plot_sph_cases.py
Travor278's picture
RheoBench working tree snapshot 2026-10-27 (sanitized mirror of Travor278/PhaseLatch) (part 12)
d513eb2 verified
Raw History Blame Contribute Delete
2.37 kB
"""Plot recorded task metrics, without interpolating physics or changing scores."""
import json
from pathlib import Path
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
root=Path(__file__).resolve().parents[1]/'results/sph_suite_20261006'
fig,axes=plt.subplots(1,3,figsize=(13.5,4.3),layout='constrained')
measured=[]
for name,color,label in [('gentle','#247561','Gentle'),('slow','#6075a8','Slow'),('fast','#c16a38','Fast')]:
d=root/name
if not (d/'report.json').exists():continue
report=json.loads((d/'report.json').read_text(encoding='utf-8'))
if report['status']!='completed':continue
rows=json.loads((d/'trajectory.json').read_text(encoding='utf-8'))
t=np.array([r['time'] for r in rows]);metrics=[r['demo_metrics'] for r in rows]
axes[0].plot(t,[1000*m['goal_error_m'] for m in metrics],color=color,label=label)
axes[1].plot(t,[1000*max(m['max_cup_relative_motion_m']) for m in metrics],color=color,label=label)
axes[2].plot(t,[100*m['max_spill_fraction'] for m in metrics],color=color,label=label)
measured.append({'case':name,'source':str(d/'report.json'),'verdict':report['demo_verdict']})
for ax in axes:
ax.axvline(12,color='#67707a',ls=':',lw=1)
ax.spines[['top','right']].set_visible(False);ax.grid(alpha=.15)
ax.set_xlabel('Simulation time (s)');ax.set_xlim(0,14)
axes[0].axhline(25,color='#67707a',ls='--',lw=.8)
axes[0].set(title='Progress to the target',ylabel='Tray target error (mm)')
axes[0].legend(frameon=False)
axes[1].axhline(2,color='#67707a',ls='--',lw=.8)
axes[1].set(title='Cup displacement relative to tray',ylabel='Historical maximum (mm)',yscale='symlog',ylim=(0,150))
axes[1].set_yticks([0,1,2,10,100],labels=['0','1','2','10','100'])
axes[2].axhline(.5,color='#67707a',ls='--',lw=.8)
axes[2].set(title='Historical liquid escape',ylabel='Maximum single-cup historical loss (%)',ylim=(0,.55))
fig.suptitle('Recorded free-cup transport: shared physics, different movement duration',fontsize=13)
fig.supxlabel('Vertical line: 12 s deadline. Horizontal lines: task limits. A sampled chart is not a continuous collision certificate.',fontsize=9)
fig.savefig(root/'task_metrics.png',dpi=180);fig.savefig(root/'task_metrics.pdf')
(root/'task_metrics.json').write_text(json.dumps(measured,indent=2),encoding='utf-8')
print(root/'task_metrics.png')