FA-64071 / Medication dosing calculations / Open access
Vial reconstitution, draw volume and waste: single-use waste accounting · case 01
Multi-use vials report the unused remainder as waste.
ROOT CAUSE
Waste is computed for every vial regardless of the single_use flag.
VERIFIED REPAIR
Report waste only for single-use vials.
Unsuccessful approach: Inverting the flag reports waste for multi-use vials and none for single-use vials.
Case contract
Input {dose_mg, vial_mg, diluent_ml, displacement_ml, single_use}. Concentration = vial_mg/(diluent_ml + displacement_ml). Draw volume = dose/concentration, rounded half-up to 0.01 mL when the volume is <= 1 mL, else to 0.1 mL. Vials = ceil(dose/vial_mg). Waste = vials*vial_mg - dose for single-use vials, else 0. Return {conc_mg_ml (4 dp), draw_ml, vials, waste_mg}.
Why this case matters
Reconstitution calculators must account for powder displacement and syringe graduations; vial counts and waste accounting are separate rules.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
vol = Fraction(str(x['dose_mg'])) / conc
q = 100 if vol <= 1 else 10
draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg']))
return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
{'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
('draw volume half step rounds up',
{'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
('dose exactly one vial',
{'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
('multi-use vial has no waste',
{'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
('draw volume half step rounds up',
{'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
('dose exactly one vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
('multi-use vial has no waste',
{'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
('draw volume half step rounds up',
{'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
('dose exactly one vial',
{'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
('multi-use vial has no waste',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
('draw volume half step rounds up',
{'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
('dose exactly one vial',
{'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
('multi-use vial has no waste',
{'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
('draw volume half step rounds up',
{'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
('dose exactly one vial',
{'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
('multi-use vial has no waste',
{'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| powder displacement dilutes vial | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0} | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0} | Passed |
| sub-millilitre draw in hundredths | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0} | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0} | Passed |
| draw volume half step rounds up | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 955.0} | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0} | Failed |
| draw volume below half step rounds down | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0} | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0} | Passed |
| dose exactly one vial | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | Passed |
| dose spanning two vials | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0} | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0} | Passed |
| multi-use vial has no waste | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 69.0} | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0} | Failed |
SHA-256 / 63c540d2063b030013a95464c248e732c66163e130dcbff132e0b5168e76b8bb
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
vol = Fraction(str(x['dose_mg'])) / conc
q = 100 if vol <= 1 else 10
draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if not x['single_use'] else 0
return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
{'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
('draw volume half step rounds up',
{'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
('dose exactly one vial',
{'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
('multi-use vial has no waste',
{'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
('draw volume half step rounds up',
{'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
('dose exactly one vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
('multi-use vial has no waste',
{'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
('draw volume half step rounds up',
{'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
('dose exactly one vial',
{'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
('multi-use vial has no waste',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
('draw volume half step rounds up',
{'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
('dose exactly one vial',
{'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
('multi-use vial has no waste',
{'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
('draw volume half step rounds up',
{'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
('dose exactly one vial',
{'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
('multi-use vial has no waste',
{'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| powder displacement dilutes vial | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0} | Failed |
| sub-millilitre draw in hundredths | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0} | Failed |
| draw volume half step rounds up | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 955.0} | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0} | Failed |
| draw volume below half step rounds down | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0} | Failed |
| dose exactly one vial | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | Passed |
| dose spanning two vials | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0} | Failed |
| multi-use vial has no waste | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 69.0} | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0} | Failed |
SHA-256 / 81b31e1809b51a58ba7ec0df8b92347aec39b281aca25a31d229cbf58a31cfb7
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
conc = Fraction(x['vial_mg']) / (Fraction(str(x['diluent_ml'])) + Fraction(str(x['displacement_ml'])))
vol = Fraction(str(x['dose_mg'])) / conc
q = 100 if vol <= 1 else 10
draw = Fraction(math.floor(vol * q + Fraction(1, 2)), q)
vials = -(-Fraction(str(x['dose_mg'])) // x['vial_mg'])
waste = vials * x['vial_mg'] - Fraction(str(x['dose_mg'])) if x['single_use'] else 0
return {'conc_mg_ml': round(float(conc), 4), 'draw_ml': float(draw), 'vials': int(vials), 'waste_mg': float(waste)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('powder displacement dilutes vial',
{'dose_mg': 450, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 37, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0}),
('draw volume half step rounds up',
{'dose_mg': 45, 'vial_mg': 1000, 'diluent_ml': 49, 'displacement_ml': 1, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 62, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0}),
('dose exactly one vial',
{'dose_mg': 250, 'vial_mg': 250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 601, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0}),
('multi-use vial has no waste',
{'dose_mg': 31, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 10.0, 'vials': 1, 'waste_mg': 0.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 41, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.82, 'vials': 1, 'waste_mg': 59.0}),
('draw volume half step rounds up',
{'dose_mg': 49, 'vial_mg': 1000, 'diluent_ml': 48, 'displacement_ml': 2, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.5, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 71, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.4, 'vials': 1, 'waste_mg': 29.0}),
('dose exactly one vial',
{'dose_mg': 500, 'vial_mg': 500, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 100.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 602, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 398.0}),
('multi-use vial has no waste',
{'dose_mg': 32, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.2, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 550, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 11.0, 'vials': 2, 'waste_mg': 450.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 29, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.58, 'vials': 1, 'waste_mg': 71.0}),
('draw volume half step rounds up',
{'dose_mg': 53, 'vial_mg': 1000, 'diluent_ml': 47, 'displacement_ml': 3, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.7, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 81, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.6, 'vials': 1, 'waste_mg': 19.0}),
('dose exactly one vial',
{'dose_mg': 750, 'vial_mg': 750, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 150.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 603, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 397.0}),
('multi-use vial has no waste',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.3, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 600, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 400.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 33, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.66, 'vials': 1, 'waste_mg': 67.0}),
('draw volume half step rounds up',
{'dose_mg': 57, 'vial_mg': 1000, 'diluent_ml': 46, 'displacement_ml': 4, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 2.9, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 92, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 1.8, 'vials': 1, 'waste_mg': 8.0}),
('dose exactly one vial',
{'dose_mg': 1000, 'vial_mg': 1000, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 200.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 604, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 396.0}),
('multi-use vial has no waste',
{'dose_mg': 34, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.4, 'vials': 1, 'waste_mg': 0.0})],
[('powder displacement dilutes vial',
{'dose_mg': 650, 'vial_mg': 500, 'diluent_ml': '9.6', 'displacement_ml': '0.4', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 13.0, 'vials': 2, 'waste_mg': 350.0}),
('sub-millilitre draw in hundredths',
{'dose_mg': 47, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 0.94, 'vials': 1, 'waste_mg': 53.0}),
('draw volume half step rounds up',
{'dose_mg': 61, 'vial_mg': 1000, 'diluent_ml': 45, 'displacement_ml': 5, 'single_use': False},
{'conc_mg_ml': 20.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0}),
('draw volume below half step rounds down',
{'dose_mg': 102, 'vial_mg': 100, 'diluent_ml': '1.8', 'displacement_ml': '0.2', 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 2.0, 'vials': 2, 'waste_mg': 98.0}),
('dose exactly one vial',
{'dose_mg': 1250, 'vial_mg': 1250, 'diluent_ml': 5, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 250.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0}),
('dose spanning two vials',
{'dose_mg': 605, 'vial_mg': 500, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': True},
{'conc_mg_ml': 50.0, 'draw_ml': 12.1, 'vials': 2, 'waste_mg': 395.0}),
('multi-use vial has no waste',
{'dose_mg': 35, 'vial_mg': 100, 'diluent_ml': 10, 'displacement_ml': 0, 'single_use': False},
{'conc_mg_ml': 10.0, 'draw_ml': 3.5, 'vials': 1, 'waste_mg': 0.0})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| powder displacement dilutes vial | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0} | {'conc_mg_ml': 50.0, 'draw_ml': 9.0, 'vials': 1, 'waste_mg': 50.0} | Passed |
| sub-millilitre draw in hundredths | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0} | {'conc_mg_ml': 50.0, 'draw_ml': 0.74, 'vials': 1, 'waste_mg': 63.0} | Passed |
| draw volume half step rounds up | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 20.0, 'draw_ml': 2.3, 'vials': 1, 'waste_mg': 0.0} | Passed |
| draw volume below half step rounds down | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0} | {'conc_mg_ml': 50.0, 'draw_ml': 1.2, 'vials': 1, 'waste_mg': 38.0} | Passed |
| dose exactly one vial | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 50.0, 'draw_ml': 5.0, 'vials': 1, 'waste_mg': 0.0} | Passed |
| dose spanning two vials | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0} | {'conc_mg_ml': 50.0, 'draw_ml': 12.0, 'vials': 2, 'waste_mg': 399.0} | Passed |
| multi-use vial has no waste | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0} | {'conc_mg_ml': 10.0, 'draw_ml': 3.1, 'vials': 1, 'waste_mg': 0.0} | Passed |
SHA-256 / 5d821a66b7acb1f569a56d8114145c7038d61ce02fad0ed5ebae8148b6851365
Verification & scope
A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:20.746347+00:00.
Case digest / 0468f20692fa0e02ea1e1d8751a0c9d64ddddeec9729369eb60e774157572fa4