broken_source:
"""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)

source:
"""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)

prompt:
Multi-use vials report the unused remainder as waste.

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}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), tgt * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), abs(tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

prompt:
Patients already partly loaded receive a full loading dose.

Input {target, current, vd_l_kg, weight_kg, f, cl_ml_min, tau_h, unit_mg}. Toy one-compartment rule: loading = max(0, (target-current)*Vd*weight/F); maintenance = target*CL*tau/F with CL in L/h = cl_ml_min*60/1000. Both are rounded half-up to a multiple of unit_mg. Return {loading_mg, maintenance_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * 70 / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

prompt:
Loading doses are about seventy times too small.

Input {target, current, vd_l_kg, weight_kg, f, cl_ml_min, tau_h, unit_mg}. Toy one-compartment rule: loading = max(0, (target-current)*Vd*weight/F); maintenance = target*CL*tau/F with CL in L/h = cl_ml_min*60/1000. Both are rounded half-up to a multiple of unit_mg. Return {loading_mg, maintenance_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] * f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 60 / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h']
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

prompt:
Oral maintenance doses are smaller than the intravenous equivalent.

Input {target, current, vd_l_kg, weight_kg, f, cl_ml_min, tau_h, unit_mg}. Toy one-compartment rule: loading = max(0, (target-current)*Vd*weight/F); maintenance = target*CL*tau/F with CL in L/h = cl_ml_min*60/1000. Both are rounded half-up to a multiple of unit_mg. Return {loading_mg, maintenance_mg}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) / 1000
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(x):
    tgt, cur = Fraction(str(x['target'])), Fraction(str(x['current']))
    f = Fraction(str(x['f']))
    u = x['unit_mg']
    vd = Fraction(str(x['vd_l_kg']))
    wt = Fraction(str(x['weight_kg']))
    cl = Fraction(x['cl_ml_min']) * 1000 / 60
    def rnd(v):
        return float(math.floor(v / u + Fraction(1, 2)) * u)
    load = max(Fraction(0), (tgt - cur) * vd * wt / f)
    maint = tgt * cl * x['tau_h'] / f
    return {'loading_mg': rnd(load), 'maintenance_mg': rnd(maint)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 71,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 6,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 700.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 13,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.5',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 240.0, 'maintenance_mg': 290.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 65,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 175.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 10,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 14.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 72,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 7,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 650.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 14,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.8',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 150.0, 'maintenance_mg': 180.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 25,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 75.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 20,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 29.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 73,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 750.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 8,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 600.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 15,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.25',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 480.0, 'maintenance_mg': 575.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 45,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 125.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 30,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 43.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 74,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 9,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 550.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 16,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.4',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 300.0, 'maintenance_mg': 360.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 85,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 225.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 40,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 58.0})],
 [('drug-naive loading',
   {'target': 15,
    'current': 0,
    'vd_l_kg': '0.7',
    'weight_kg': 75,
    'f': 1,
    'cl_ml_min': 100,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 800.0, 'maintenance_mg': 1100.0}),
  ('partial existing level credited',
   {'target': 20,
    'current': 10,
    'vd_l_kg': '0.5',
    'weight_kg': 80,
    'f': '0.8',
    'cl_ml_min': 80,
    'tau_h': 8,
    'unit_mg': 25},
   {'loading_mg': 500.0, 'maintenance_mg': 950.0}),
  ('level above target gives no load',
   {'target': 10,
    'current': 17,
    'vd_l_kg': '0.6',
    'weight_kg': 70,
    'f': 1,
    'cl_ml_min': 90,
    'tau_h': 12,
    'unit_mg': 50},
   {'loading_mg': 0.0, 'maintenance_mg': 650.0}),
  ('oral bioavailability maintenance',
   {'target': 2,
    'current': 0,
    'vd_l_kg': '1.0',
    'weight_kg': 60,
    'f': '0.6',
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 5},
   {'loading_mg': 200.0, 'maintenance_mg': 240.0}),
  ('half unit rounds up',
   {'target': 5,
    'current': 0,
    'vd_l_kg': '0.5',
    'weight_kg': 105,
    'f': 1,
    'cl_ml_min': 25,
    'tau_h': 6,
    'unit_mg': 25},
   {'loading_mg': 275.0, 'maintenance_mg': 50.0}),
  ('slow clearance long interval',
   {'target': 1,
    'current': 0,
    'vd_l_kg': '0.2',
    'weight_kg': 50,
    'f': 1,
    'cl_ml_min': 50,
    'tau_h': 24,
    'unit_mg': 1},
   {'loading_mg': 10.0, 'maintenance_mg': 72.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)

prompt:
Maintenance doses are sixty times too small.

Input {target, current, vd_l_kg, weight_kg, f, cl_ml_min, tau_h, unit_mg}. Toy one-compartment rule: loading = max(0, (target-current)*Vd*weight/F); maintenance = target*CL*tau/F with CL in L/h = cl_ml_min*60/1000. Both are rounded half-up to a multiple of unit_mg. Return {loading_mg, maintenance_mg}.

split: open-access