{
  "method": "Trust-constr interior-point radius minimization with analytic semicircle containment, contact-specific intersection-area constraints, and official-polygon mixed-integer rounding repair.",
  "seed": 22002,
  "official_valid": true,
  "official_score": "2.94852695",
  "official_score_full": 2.948526950912552,
  "solution": [
    {
      "x": 0.545425,
      "y": 0.67215,
      "theta": -0.570778
    },
    {
      "x": 1.135484,
      "y": -1.23874,
      "theta": 2.227365
    },
    {
      "x": -0.584124,
      "y": -0.217653,
      "theta": -1.671787
    },
    {
      "x": 1.843118,
      "y": 0.631801,
      "theta": -0.722762
    },
    {
      "x": 0.278186,
      "y": 1.928675,
      "theta": 2.264578
    },
    {
      "x": -0.723715,
      "y": 1.809349,
      "theta": 3.126118
    },
    {
      "x": -1.624637,
      "y": 1.076193,
      "theta": -2.992325
    },
    {
      "x": -0.56981,
      "y": 0.785952,
      "theta": -1.682231
    },
    {
      "x": 0.032918,
      "y": 1.724683,
      "theta": -0.877015
    },
    {
      "x": 1.261991,
      "y": 1.484613,
      "theta": 0.453135
    },
    {
      "x": -1.944933,
      "y": -0.121111,
      "theta": -2.464295
    },
    {
      "x": -1.573106,
      "y": -1.149938,
      "theta": -1.641622
    },
    {
      "x": 1.049635,
      "y": -2.567295,
      "theta": 1.95895
    },
    {
      "x": -0.789401,
      "y": -1.781407,
      "theta": -0.792106
    },
    {
      "x": 1.811166,
      "y": -0.718041,
      "theta": -0.914204
    }
  ],
  "solution_json": "[\n  {\n    \"x\": 0.545425,\n    \"y\": 0.67215,\n    \"theta\": -0.570778\n  },\n  {\n    \"x\": 1.135484,\n    \"y\": -1.23874,\n    \"theta\": 2.227365\n  },\n  {\n    \"x\": -0.584124,\n    \"y\": -0.217653,\n    \"theta\": -1.671787\n  },\n  {\n    \"x\": 1.843118,\n    \"y\": 0.631801,\n    \"theta\": -0.722762\n  },\n  {\n    \"x\": 0.278186,\n    \"y\": 1.928675,\n    \"theta\": 2.264578\n  },\n  {\n    \"x\": -0.723715,\n    \"y\": 1.809349,\n    \"theta\": 3.126118\n  },\n  {\n    \"x\": -1.624637,\n    \"y\": 1.076193,\n    \"theta\": -2.992325\n  },\n  {\n    \"x\": -0.56981,\n    \"y\": 0.785952,\n    \"theta\": -1.682231\n  },\n  {\n    \"x\": 0.032918,\n    \"y\": 1.724683,\n    \"theta\": -0.877015\n  },\n  {\n    \"x\": 1.261991,\n    \"y\": 1.484613,\n    \"theta\": 0.453135\n  },\n  {\n    \"x\": -1.944933,\n    \"y\": -0.121111,\n    \"theta\": -2.464295\n  },\n  {\n    \"x\": -1.573106,\n    \"y\": -1.149938,\n    \"theta\": -1.641622\n  },\n  {\n    \"x\": 1.049635,\n    \"y\": -2.567295,\n    \"theta\": 1.95895\n  },\n  {\n    \"x\": -0.789401,\n    \"y\": -1.781407,\n    \"theta\": -0.792106\n  },\n  {\n    \"x\": 1.811166,\n    \"y\": -0.718041,\n    \"theta\": -0.914204\n  }\n]\n",
  "solution_sha256": "cefac3368caae7f9dea0c4cdc0e87d869f3a9bd76ba75292b1cd4b7fff7c8fb9",
  "mec": {
    "cx": -0.0001819080616875258,
    "cy": 0.00013448997007248039,
    "radius": 2.948526950912552
  },
  "max_pair_area": 9.997822348073146e-07,
  "inherited_baseline": {
    "source": "after-published and identical task rows",
    "official_score": "2.94852695",
    "official_score_full": 2.948526950912552,
    "source_sha256": "89ffaa96cbc8f60cbce1ebe7c61e0bfac270d013b5aff71bc9d5c7da1a374161",
    "exact_circular_max_pair_area": 1.0013726918153831e-06,
    "solution": [
      {
        "x": 0.545425,
        "y": 0.67215,
        "theta": -0.570778
      },
      {
        "x": 1.135484,
        "y": -1.23874,
        "theta": 2.227365
      },
      {
        "x": -0.584124,
        "y": -0.217653,
        "theta": -1.671787
      },
      {
        "x": 1.843118,
        "y": 0.631801,
        "theta": -0.722762
      },
      {
        "x": 0.278186,
        "y": 1.928675,
        "theta": 2.264578
      },
      {
        "x": -0.723715,
        "y": 1.809349,
        "theta": 3.126118
      },
      {
        "x": -1.624637,
        "y": 1.076193,
        "theta": -2.992325
      },
      {
        "x": -0.56981,
        "y": 0.785952,
        "theta": -1.682231
      },
      {
        "x": 0.032918,
        "y": 1.724683,
        "theta": -0.877015
      },
      {
        "x": 1.261991,
        "y": 1.484613,
        "theta": 0.453135
      },
      {
        "x": -1.944933,
        "y": -0.121111,
        "theta": -2.464295
      },
      {
        "x": -1.573106,
        "y": -1.149938,
        "theta": -1.641622
      },
      {
        "x": 1.049635,
        "y": -2.567295,
        "theta": 1.95895
      },
      {
        "x": -0.789401,
        "y": -1.781407,
        "theta": -0.792106
      },
      {
        "x": 1.811166,
        "y": -0.718041,
        "theta": -0.914204
      }
    ]
  },
  "best_new_score": null,
  "best_fresh_score": 3.313079519893664,
  "strict_radius": null,
  "structure": {
    "full_disks": 0,
    "full_disk_pairs": [],
    "sliding_seams": [
      {
        "pair": [
          4,
          8
        ],
        "offset": 4.730659698137796e-07,
        "slide": 0.3190127393816369,
        "angle_from_opposed": 3.464102071859543e-07
      },
      {
        "pair": [
          1,
          14
        ],
        "offset": 1.6987247092370428e-05,
        "slide": 0.8530378733892379,
        "angle_from_opposed": 2.365358979350418e-05
      }
    ],
    "boundary_arc_contacts": [
      3,
      4,
      5,
      6,
      9,
      10,
      11,
      13,
      14
    ],
    "boundary_endpoint_contacts": [
      12
    ],
    "interior": [
      0,
      1,
      2,
      7,
      8
    ],
    "boundary_contact_distance_tolerance": 2e-06,
    "flats": "The near-opposed seams slide tangentially without making complete disks. The outermost disk center belongs to an inward-facing semicircle with its flat side outward and its endpoints against the container.",
    "symmetry": "No apparent rotational or mirror symmetry. The boundary centers have uneven angular spacing.",
    "indices": "zero-based"
  },
  "scorer_check": {
    "seed": 2195491031,
    "random": 12,
    "tight": 13,
    "sample": 1,
    "rounded_input_changed": 25,
    "official_validity_disagreements": 0,
    "exact_vs_official_validity_disagreements": 3,
    "cases_with_pair_cap_crossings": 4,
    "max_mec_delta": 2.078603955624203e-11,
    "max_valid_score_delta": 1.4699352846037073e-13,
    "max_exact_area_delta_vs_32769_vertices": 2.9586493255351343e-09,
    "max_abs_area_jacobian_error_vs_central_difference": 0.0022540136158789026,
    "coincident_center_mec": 1.0,
    "coincident_center_official_mec": 1.0,
    "official_tests_passed": 31
  },
  "runs": [
    {
      "seed": 2549098994,
      "start_kind": "baseline",
      "minutes": 1.487665963250523,
      "attempts": 2020,
      "valid_count": 2,
      "best_radius": 2.948526950912552,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "polygon overlap": 2018
      }
    },
    {
      "seed": 3971972377,
      "start_kind": "fresh-ring",
      "minutes": 1.3877264284528792,
      "attempts": 2012,
      "valid_count": 508,
      "best_radius": 3.313079519893664,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "polygon overlap": 1504
      }
    },
    {
      "seed": 2137454080,
      "start_kind": "fresh-ring",
      "minutes": 1.3784785505228987,
      "attempts": 2034,
      "valid_count": 515,
      "best_radius": 3.4939490125407784,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "polygon overlap": 1519
      }
    },
    {
      "seed": 1833721555,
      "start_kind": "baseline-local",
      "minutes": 5.9407959664550924,
      "attempts": 728,
      "valid_count": 75,
      "best_radius": 2.948526950912552,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "rounded overlap": 653,
        "termination": "Exit 143. Counts and elapsed time reflect last completed checkpoint."
      }
    },
    {
      "seed": 117322817,
      "start_kind": "baseline-local, dense rigid phases",
      "minutes": 2.9502502523517857,
      "attempts": 5874,
      "valid_count": 0,
      "best_radius": 2.948526950912552,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "rounded overlap": 5874,
        "termination": "Exit 143. Counts and elapsed time reflect last completed checkpoint."
      }
    },
    {
      "seed": 3758207164,
      "start_kind": "baseline-local, bounded-radius integer repair",
      "minutes": 3.049017578192676,
      "attempts": 31,
      "valid_count": 0,
      "best_radius": 2.948526950912552,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "rounded overlap": 31,
        "termination": "Exit 143. Counts and elapsed time reflect last completed checkpoint."
      }
    },
    {
      "seed": 2298408242,
      "start_kind": "baseline-local, short integer-repair repeat",
      "minutes": 0.8211378277434657,
      "attempts": 10,
      "valid_count": 0,
      "best_radius": 2.948526950912552,
      "score_kind": "official 4096-point polygons and analytic MEC",
      "errors": {
        "rounded overlap": 10
      }
    }
  ],
  "repo_commit": "78a78626f098cd236f3a09bb2cb242f72951599d",
  "source_urls": [
    "https://www.paradigm.xyz/puzzles/packing/about",
    "https://github.com/benedictbrady/shape-packing-challenge",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/README.md",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/src/semicircle_packing/geometry.py",
    "https://raw.githubusercontent.com/benedictbrady/shape-packing-challenge/78a78626f098cd236f3a09bb2cb242f72951599d/src/semicircle_packing/scoring.py"
  ],
  "notes": [
    "Sample was valid at 3.500000 in the official CLI. Final validation used the unmodified validate_and_score and _load_solution in a separately cloned copy at the pinned commit.",
    "A separate worker validation is pending. The clean-clone validation was performed by this item.",
    "Direct max area uses official 4096-point polygons over all 105 pairs. Maximum pair is [14, 13].",
    "The scorer check compares analytic Green-theorem areas with 32769-point polygon areas and exact farthest-point containment against the official MEC. The Jacobian comparison uses finite differences and serves as a numerical diagnostic. Direct polygon validation breaks ties near the overlap cap.",
    "Broad runs fitted contact-specific offsets between circular and official polygon areas, then tried rigid grid phases. The local baseline run evaluated official polygon area directly at each active contact and used circular shape derivatives for the approximate Jacobian. The mixed-integer repair searched nearby grid points using linearized constraints, then rechecked all pairs and the exact containment radius.",
    "Attempt counts include rounded checkpoints and rounding-repair candidates. Valid counts use the all-pairs polygon filter and exact containment model. Local valid counts exclude the inherited packing. Every retained improvement was independently rescored by validate_and_score.",
    "The two fresh starts used independently randomized angular offsets, radial positions and orientations on an 11+4 scaffold, with no placements inherited from the published configuration.",
    "Two startup attempts hit an SLSQP Jacobian dtype error before optimization. They were restarted with a float64 Jacobian.",
    "The zero-padding local model shrank the radius by 3.905883406e-7 before coordinate rounding. This is an optimization diagnostic, separate from scored solutions.",
    "best_new_score records an official improvement over the re-scored inherited baseline. best_fresh_score records the strongest independent restart.",
    "Strict zero-area radius was unmeasured. No sign-in or submission was performed.",
    "The inherited fallback already scores below the five-decimal threshold of 2.94853. The search has not improved its full-precision score."
  ],
  "scorer_source": {
    "search.py": "import json, math, sys, time\nfrom pathlib import Path\nimport numpy as np\nimport shapely\nfrom scipy.optimize import minimize, NonlinearConstraint\nfrom semicircle_packing.geometry import Semicircle\nfrom semicircle_packing.scoring import validate_and_score\n\nI,J = np.triu_indices(15,1)\nKEYS = ('x','y','theta')\ndef load(path):\n    return np.array([[p[k] for k in KEYS] for p in json.loads(Path(path).read_text())])\ndef rounded(x):\n    return np.array([round(float(v),6) for v in np.ravel(x)]).reshape(15,3)\ndef save(path,x):\n    Path(path).write_text(json.dumps([dict(zip(KEYS,p)) for p in rounded(x)],indent=2)+'\\n')\ndef official(x):\n    return validate_and_score([Semicircle(*p) for p in rounded(x)])\ndef cross(a,b):\n    return a[0]*b[1]-a[1]*b[0]\ndef boundary(d,theta,phi,own):\n    # Unit disk at the origin, second disk centered at d. Integrate the\n    # surviving CCW arc and diameter using Green's theorem. Return area\n    # integral and rigid-motion derivatives from the same boundary pieces.\n    c,s=math.cos(theta),math.sin(theta)\n    a,b=math.cos(phi),math.sin(phi)\n    x,y=d\n    r=math.hypot(x,y)\n    h=x*a+y*b\n    cuts=[-math.pi/2,math.pi/2]\n    roots=[]\n    if 1e-13 < r < 2:\n        t=math.atan2(y,x)\n        q=math.acos(r/2)\n        roots.extend((t-q,t+q))\n    if abs(h)<1:\n        q=math.acos(h)\n        roots.extend((phi-q,phi+q))\n    for t in roots:\n        t=(t-theta+math.pi)%(2*math.pi)-math.pi\n        if abs(t)<math.pi/2:\n            cuts.append(t)\n    cuts.sort()\n    area=gx=gy=gt=0.\n    for l,u in zip(cuts,cuts[1:]):\n        t=theta+(l+u)/2\n        px,py=math.cos(t),math.sin(t)\n        if ((r<1e-13 and own) or (r>=1e-13 and px*x+py*y>=r*r/2)) and px*a+py*b>=h:\n            nx=math.sin(theta+u)-math.sin(theta+l)\n            ny=math.cos(theta+l)-math.cos(theta+u)\n            area+=u-l\n            gx+=nx\n            gy+=ny\n    # Chord runs from +v to -v, where v is the left perpendicular.\n    vx,vy=-s,c\n    proj=x*vx+y*vy\n    perp=x*c+y*s\n    if abs(perp)<1:\n        q=math.sqrt(1-perp*perp)\n        l,u=max(-1.,proj-q),min(1.,proj+q)\n        slope=a*vx+b*vy\n        if abs(slope)>1e-13:\n            if slope>0: l=max(l,h/slope)\n            else: u=min(u,h/slope)\n        elif h>1e-13 or (abs(h)<=1e-13 and a*c+b*s>0 and not own):\n            u=l\n        if u>l:\n            gx-=c*(u-l)\n            gy-=s*(u-l)\n            gt+=(u*u-l*l)/2\n    return area,gx,gy,gt\n\ndef pair(p,q):\n    dx,dy=q[:2]-p[:2]\n    if dx*dx+dy*dy>=4:\n        return 0.,np.zeros(3),np.zeros(3)\n    a,gx,gy,gt=boundary((dx,dy),p[2],q[2],True)\n    b,hx,hy,ht=boundary((-dx,-dy),q[2],p[2],False)\n    # Shift the second local boundary integral into the first frame.\n    value=max(0.,(a+b+dx*hx+dy*hy)/2)\n    return value,np.array([gx,gy,gt]),np.array([hx,hy,ht])\n\ndef far(p,c):\n    d=p[:,:2]-c\n    n=np.column_stack((np.cos(p[:,2]),np.sin(p[:,2])))\n    v=np.column_stack((-n[:,1],n[:,0]))\n    r=np.linalg.norm(d,axis=1)\n    side=np.sum(d*n,axis=1)\n    along=np.sum(d*v,axis=1)\n    arc=side>=0\n    direction=np.where(arc[:,None],np.where(r[:,None]>0,d/np.maximum(r[:,None],1e-100),n),np.where(along[:,None]>=0,v,-v))\n    return d+direction,np.where(arc,0.,-2*side*np.where(along>=0,1,-1))\n\ndef contain(z):\n    p=z[:45].reshape(15,3)\n    f,t=far(p,z[45:47])\n    # Keeping both endpoints explicitly avoids the cusp when both are active.\n    d=p[:,:2]-z[45:47]\n    n=np.column_stack((np.cos(p[:,2]),np.sin(p[:,2])))\n    v=np.column_stack((-n[:,1],n[:,0]))\n    arc=(d*n).sum(axis=1)>=0\n    f=np.vstack((f,d+v,d-v))\n    g=np.zeros((45,48))\n    rows=np.arange(45)\n    ind=3*(rows%15)\n    g[rows,ind]=-2*f[:,0]\n    g[rows,ind+1]=-2*f[:,1]\n    g[rows,ind+2]=-np.concatenate((t, -2*(d*n).sum(axis=1), 2*(d*n).sum(axis=1)))\n    # For inward-facing arcs the endpoints already enforce containment.\n    g[:15][~arc]=0\n    g[:15][~arc,47]=2*z[47]\n    g[15:,45:47]=2*f[15:]\n    g[:15,45:47]=np.where(arc[:,None],2*f[:15],0.)\n    g[:,47]=2*z[47]\n    values=z[47]**2-(f*f).sum(axis=1)\n    values[:15]=np.where(arc,values[:15],z[47]**2-(d*d).sum(axis=1)-1)\n    # Use the perpendicular support at the transition, with its derivative.\n    g[:15][~arc,45:47]=2*d[~arc]\n    for i in np.flatnonzero(~arc):\n        g[i,3*i:3*i+2]=-2*d[i]\n    return values,g\n\ndef mec(p):\n    z=np.r_[p.ravel(),p[:,:2].mean(axis=0),5.]\n    fun=lambda t: t[2]\n    def con(t):\n        v,g=contain(np.r_[z[:45],t])\n        return v,g[:,45:]\n    fit=minimize(fun,z[45:],jac=lambda t: np.array([0.,0.,1.]),method='SLSQP',\n                 constraints={'type':'ineq','fun':lambda t:con(t)[0],'jac':lambda t:con(t)[1]},\n                 options={'ftol':1e-13,'maxiter':100})\n    c=fit.x[:2]\n    return np.r_[c,np.linalg.norm(far(p,c)[0],axis=1).max()]\n\ndef polygons(p):\n    t=p[:,2,None]+np.linspace(-np.pi/2,np.pi/2,4096)\n    xy=p[:,None,:2]+np.stack((np.cos(t),np.sin(t)),axis=2)\n    return shapely.polygons(xy)\ndef poly_areas(p,ii=I,jj=J):\n    polys=polygons(p)\n    return shapely.area(shapely.intersection(polys[ii],polys[jj]))\n\ndef score(p):\n    p=rounded(p)\n    return mec(p),poly_areas(p).max()\n\ndef search(start,seed,kind,seconds,out):\n    rng=np.random.default_rng(seed)\n    begin=time.monotonic()\n    attempts=valid=0\n    best=None\n    errors={}\n    last=0.\n    def retain(p):\n        nonlocal attempts,valid,best,last\n        elapsed=time.monotonic()-begin\n        p=rounded(p)\n        attempts+=1\n        if poly_areas(p).max()>1e-6:\n            errors['polygon overlap']=errors.get('polygon overlap',0)+1\n            return\n        radius=mec(p)[2]\n        valid+=1\n        if best is None or radius<best:\n            check=official(p)\n            if not check.valid:\n                errors['official rejection']=errors.get('official rejection',0)+1\n                return\n            best=check.score\n            save(out,p)\n            print(kind,attempts,format(best,'.12f'),flush=True)\n        if elapsed-last>=60:\n            last=elapsed\n            report()\n    def report():\n        data=dict(seed=seed,start_kind=kind,minutes=(time.monotonic()-begin)/60,\n                  attempts=attempts,valid_count=valid,best_radius=best,\n                  score_kind='official 4096-point polygons and analytic MEC',errors=errors)\n        Path(out+'.run').write_text(json.dumps(data))\n    retain(start)\n    z=np.r_[start.ravel(),mec(start)]\n    for stage in range(4):\n        p=z[:45].reshape(15,3)\n        ii,jj=I,J\n        exact=np.array([pair(p[i],p[j])[0] for i,j in zip(ii,jj)])\n        if stage or kind=='baseline':\n            # Limit polygon calls to contacts close to saturation.\n            active=exact>6e-7\n            delta=np.zeros(len(ii))\n            delta[active]=exact[active]-poly_areas(p,ii[active],jj[active])\n        else:\n            delta=np.zeros(len(ii))\n        allowance=1e-6+delta\n        cache={}\n        def areas(w):\n            if 'w' not in cache or not np.array_equal(cache['w'],w):\n                v=np.empty(len(ii))\n                g=np.zeros((len(ii),48))\n                p=w[:45].reshape(15,3)\n                for k,(i,j) in enumerate(zip(ii,jj)):\n                    a,b,c=pair(p[i],p[j])\n                    v[k]=allowance[k]-a\n                    g[k,3*i:3*i+3]=-b\n                    g[k,3*j:3*j+3]=-c\n                cache.update(w=w.copy(),v=1000*v,g=1000*g)\n            return cache['v'],cache['g']\n        area_con=NonlinearConstraint(lambda w:areas(w)[0],0,np.inf,jac=lambda w:areas(w)[1])\n        wall=NonlinearConstraint(lambda w:contain(w)[0],0,np.inf,jac=lambda w:contain(w)[1])\n        def callback(w,state):\n            elapsed=time.monotonic()-begin\n            if state.niter%25==0 and (state.constr_violation<0.00015 or elapsed-last>=60):\n                retain(w[:45])\n            if elapsed-last>=60:\n                report()\n            return elapsed>seconds\n        objective=np.eye(48)[-1]\n        fit=minimize(lambda w:w[-1],z,jac=lambda w:objective,hess=lambda w:np.zeros((48,48)),\n                     method='trust-constr',constraints=[wall,area_con],callback=callback,\n                     options={'maxiter':350,'gtol':2e-11,'initial_barrier_parameter':1e-5,\n                              'initial_barrier_tolerance':1e-5,'initial_tr_radius':.02})\n        z=fit.x\n        print('stage',stage,fit.nit,z[-1],fit.constr_violation,flush=True)\n        # Rotation and translation are continuous symmetries. Round across\n        # different grid phases and verify all overlaps for each phase.\n        for k in range(501):\n            if time.monotonic()-begin>seconds: break\n            p=z[:45].reshape(15,3).copy()\n            if k:\n                angle=rng.uniform(-1e-4,1e-4)\n                c,s=math.cos(angle),math.sin(angle)\n                p[:,:2]=p[:,:2]@np.array([[c,s],[-s,c]])+rng.uniform(-.5e-6,.5e-6,2)\n                p[:,2]+=angle\n            retain(p)\n        if time.monotonic()-begin>seconds: break\n    report()\n\nif __name__=='__main__':\n    kind,seed,seconds,out=sys.argv[1:5]\n    rng=np.random.default_rng(int(seed))\n    if kind=='baseline':\n        start=load(sys.argv[5])\n    else:\n        ang=np.linspace(0,2*np.pi,11,endpoint=False)+rng.normal(0,.15,11)\n        inner=np.linspace(0,2*np.pi,4,endpoint=False)+rng.uniform(0,2*np.pi)\n        t=np.r_[ang,inner]\n        r=np.r_[rng.uniform(1.8,2.4,11),rng.uniform(.15,.85,4)]\n        start=np.column_stack((r*np.cos(t),r*np.sin(t),t+rng.normal(0,1.2,15)))\n    search(start,int(seed),kind,float(seconds),out)\n",
    "polish.py": "import sys,time,json\nimport numpy as np\nfrom scipy.optimize import minimize, NonlinearConstraint, Bounds, milp, LinearConstraint\nfrom pathlib import Path\nfrom search import *\n\ndef polish(p,seed,seconds,out,cycles=80):\n    rng=np.random.default_rng(seed)\n    begin=time.monotonic()\n    initial=official(p)\n    best=initial.score\n    save(out,p)\n    attempts=valid=0\n    errors={}\n    last=begin\n    def report():\n        Path(out+'.run').write_text(json.dumps(dict(seed=seed,start_kind='baseline-local',\n            minutes=(time.monotonic()-begin)/60,attempts=attempts,valid_count=valid,\n            best_radius=best,score_kind='official 4096-point polygons and analytic MEC',errors=errors)))\n    def retain(p):\n        nonlocal attempts,valid,best,last\n        attempts+=1\n        p=rounded(p)\n        if poly_areas(p).max()>1e-6:\n            errors['rounded overlap']=errors.get('rounded overlap',0)+1\n        else:\n            valid+=1\n            if mec(p)[2]<best-1e-11:\n                r=official(p)\n                if r.valid and r.score<best:\n                    best=r.score\n                    save(out,p)\n                    print('local',attempts,format(best,'.12f'),flush=True)\n        if time.monotonic()-last>=59:\n            report()\n            last=time.monotonic()\n\n    z=np.r_[p.ravel(),mec(p)]\n    active=poly_areas(p)>1e-7\n    ii,jj=I[active],J[active]\n    unit=1e-6\n    eye=np.eye(48)[-1]\n    def wall(w):\n        v,g=contain(z+unit*w)\n        return v/(unit*6),g/6\n    cache={}\n    def area(w):\n        if 'w' not in cache or not np.array_equal(cache['w'],w):\n            q=(z+unit*w)[:45].reshape(15,3)\n            value=poly_areas(q,ii,jj)\n            g=np.zeros((len(ii),48))\n            for k,(i,j) in enumerate(zip(ii,jj)):\n                _,u,v=pair(q[i],q[j])\n                g[k,3*i:3*i+3]=-u\n                g[k,3*j:3*j+3]=-v\n            cache.update(w=w.copy(),v=(1e-6-value)/unit,g=g)\n        return cache['v'],cache['g']\n    def constraint(fun,pad):\n        return NonlinearConstraint(lambda w:fun(w)[0]-pad,0,np.inf,jac=lambda w:fun(w)[1])\n    def callback(w,state):\n        if state.niter%30==0:\n            retain((z+unit*w)[:45])\n        return time.monotonic()-begin>seconds\n    for pad in (0.,.001,.004,.009,.02):\n        fit=minimize(lambda w:w[-1],np.zeros(48),jac=lambda w:eye,hess=lambda w:np.zeros((48,48)),\n            method='trust-constr',bounds=Bounds(-50,50),\n            constraints=[constraint(wall,0),constraint(area,pad)],callback=callback,\n            options={'maxiter':160,'gtol':1e-8,'initial_barrier_parameter':1e-4,\n                     'initial_barrier_tolerance':1e-4,'initial_tr_radius':.35})\n        print('local fit',pad,fit.nit,fit.x[-1],fit.constr_violation,flush=True)\n        continuous=z+unit*fit.x\n        for k in range(abs(cycles)):\n            if time.monotonic()-begin>=seconds: break\n            q=continuous.copy()\n            p=q[:45].reshape(15,3)\n            angle=rng.uniform(-.002,.002) if k else 0.\n            c,s=np.cos(angle),np.sin(angle)\n            rot=np.array([[c,s],[-s,c]])\n            shift=rng.uniform(-.5e-6,.5e-6,2) if k else np.zeros(2)\n            p[:,:2]=p[:,:2]@rot+shift\n            p[:,2]+=angle\n            q[45:47]=q[45:47]@rot+shift\n            retain(p)\n            if cycles>80: continue\n            p[:]=rounded(p)\n            v,g=contain(q)\n            v=v/(unit*6)\n            g=g/6\n            select=v<12\n            a=(1e-6-poly_areas(p,ii,jj))/unit\n            h=np.zeros((len(ii),48))\n            for t,(i,j) in enumerate(zip(ii,jj)):\n                _,b,c=pair(p[i],p[j])\n                h[t,3*i:3*i+3]=-b\n                h[t,3*j:3*j+3]=-c\n            for n in (2.,5.):\n                fit_int=milp(eye,integrality=np.r_[np.ones(45),np.zeros(3)],\n                    bounds=Bounds(np.r_[np.full(45,-n),-n,-n,-20.],\n                                  np.r_[np.full(45,n),n,n,min(20.,(best-q[47])/unit-.005) if cycles<0 else 20.]),\n                    constraints=LinearConstraint(np.vstack((g[select],h)),\n                        np.r_[-v[select],-a+.0003],np.inf),\n                    options={'time_limit':4. if cycles<0 else .65,'mip_rel_gap':.002})\n                if fit_int.x is not None:\n                    retain(p+unit*fit_int.x[:45].reshape(15,3))\n            if time.monotonic()-last>=59:\n                report()\n                last=time.monotonic()\n        report()\n        if time.monotonic()-begin>=seconds: break\n\nif __name__=='__main__':\n    src,seed,seconds,out,*rest=sys.argv[1:]\n    polish(load(src),int(seed),float(seconds),out,*map(int,rest))\n"
  },
  "commands": [
    "mkdir -p bin && curl -fLsS https://github.com/astral-sh/uv/releases/download/0.9.30/uv-x86_64-unknown-linux-gnu.tar.gz | tar xz --strip-components=1 -C bin",
    "Derived seeds are the first eight draws of numpy.random.default_rng(22002).integers(0, 2**32, size=8).",
    "git clone https://github.com/benedictbrady/shape-packing-challenge official",
    "git -C official checkout --detach 78a78626f098cd236f3a09bb2cb242f72951599d",
    "(cd official && UV_CACHE_DIR=../uv-cache ../bin/uv sync && UV_CACHE_DIR=../uv-cache ../bin/uv run python run.py)",
    "(cd official && UV_CACHE_DIR=../uv-cache ../bin/uv pip install --python .venv/bin/python scipy==1.17.1 numpy==2.5.5 shapely==2.2.0)",
    "Extract scorer_source files alongside official/. Save inherited_baseline.solution as baseline.json.",
    "OPENBLAS_NUM_THREADS=1 timeout 470 official/.venv/bin/python search.py baseline 2549098994 400 base-out.json baseline.json",
    "OPENBLAS_NUM_THREADS=1 timeout 460 official/.venv/bin/python search.py fresh-ring 3971972377 400 fresh-0.json",
    "OPENBLAS_NUM_THREADS=1 timeout 460 official/.venv/bin/python search.py fresh-ring 2137454080 400 fresh-1.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470 official/.venv/bin/python polish.py baseline.json 1833721555 420 polish.json",
    "OPENBLAS_NUM_THREADS=1 timeout 470 official/.venv/bin/python polish.py baseline.json 117322817 420 phases.json 4300",
    "OPENBLAS_NUM_THREADS=1 timeout 467 official/.venv/bin/python polish.py baseline.json 3758207164 420 branch.json -48",
    "OPENBLAS_NUM_THREADS=1 timeout 80 official/.venv/bin/python polish.py baseline.json 2298408242 45 final-short.json -48",
    "Save solution_json verbatim to solution.json and use uv run python run.py /path/to/solution.json in a clean clone.",
    "In the clean clone use from run import _load_solution and from semicircle_packing.scoring import validate_and_score, then print repr(result.score) and format(result.score, \".8f\") for validate_and_score(_load_solution(path))."
  ],
  "plot": {
    "media_type": "image/svg+xml",
    "svg": "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 500 535\" role=\"img\" aria-label=\"Packing of 15 semicircles\"><rect width=\"500\" height=\"535\" fill=\"white\"/><text x=\"250\" y=\"25\" text-anchor=\"middle\" font-family=\"sans-serif\" font-size=\"17\" fill=\"#172b41\">15 unit semicircles · R = 2.94852695</text><circle cx=\"250\" cy=\"268\" r=\"215\" fill=\"#f8fafc\" stroke=\"#172b41\" stroke-width=\"2\"/><path d=\"M250.38792,280.35704 A72.91777,72.91777 0 0 0 329.18095,157.63922 Z\" fill=\"hsl(0.00,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"317.3959\" y=\"236.7266\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">0</text><path d=\"M390.56776,313.82677 A72.91777,72.91777 0 0 0 275.05269,402.84515 Z\" fill=\"hsl(137.51,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"312.7811\" y=\"332.3451\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">1</text><path d=\"M134.87401,276.52907 A72.91777,72.91777 0 0 0 279.96648,291.23208 Z\" fill=\"hsl(275.02,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"204.1121\" y=\"316.5264\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">2</text><path d=\"M336.17723,276.62728 A72.91777,72.91777 0 0 0 432.64140,167.25330 Z\" fill=\"hsl(52.52,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"409.0185\" y=\"243.6447\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">3</text><path d=\"M326.35958,80.74792 A72.91777,72.91777 0 0 0 214.23636,174.00234 Z\" fill=\"hsl(190.03,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"249.3157\" y=\"102.1474\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">4</text><path d=\"M198.36992,63.16708 A72.91777,72.91777 0 0 0 196.11325,208.98515 Z\" fill=\"hsl(327.54,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"164.4325\" y=\"135.5684\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">5</text><path d=\"M120.70447,117.42928 A72.91777,72.91777 0 0 0 142.39225,261.64316 Z\" fill=\"hsl(105.05,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"99.1002\" y=\"194.4160\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">6</text><path d=\"M135.99849,202.59118 A72.91777,72.91777 0 0 0 280.92949,218.80870 Z\" fill=\"hsl(242.56,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"204.8150\" y=\"243.3094\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">7</text><path d=\"M196.35195,188.87696 A72.91777,72.91777 0 0 0 308.47520,95.62258 Z\" fill=\"hsl(20.06,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"273.3958\" y=\"167.4775\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">8</text><path d=\"M373.95723,225.31398 A72.91777,72.91777 0 0 0 310.11243,94.19631 Z\" fill=\"hsl(157.57,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"371.5363\" y=\"145.3901\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">9</text><path d=\"M62.49630,220.01839 A72.91777,72.91777 0 0 0 153.88989,333.66351 Z\" fill=\"hsl(295.08,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"82.6229\" y=\"297.4045\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">10</text><path d=\"M62.57093,346.70058 A72.91777,72.91777 0 0 0 208.04084,357.02085 Z\" fill=\"hsl(72.59,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"132.9838\" y=\"384.5914\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">11</text><path d=\"M394.04368,427.61330 A72.91777,72.91777 0 0 0 259.05693,482.80915 Z\" fill=\"hsl(210.10,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"314.1312\" y=\"424.8392\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">12</text><path d=\"M140.54656,449.11966 A72.91777,72.91777 0 0 0 244.35725,346.69240 Z\" fill=\"hsl(347.60,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"215.4980\" y=\"421.2634\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">13</text><path d=\"M324.32296,364.87831 A72.91777,72.91777 0 0 0 439.83593,275.85720 Z\" fill=\"hsl(125.11,60%,75%)\" stroke=\"#24354a\" stroke-width=\"0.8\"/><text x=\"402.1092\" y=\"346.3582\" text-anchor=\"middle\" dominant-baseline=\"central\" font-family=\"sans-serif\" font-size=\"12\" fill=\"#172b41\">14</text></svg>"
  },
  "best_fresh_solution": [
    {
      "x": 2.176051,
      "y": -0.110054,
      "theta": 0.261074
    },
    {
      "x": 1.976715,
      "y": 0.965203,
      "theta": 1.367376
    },
    {
      "x": 0.389457,
      "y": 2.191718,
      "theta": 0.43222
    },
    {
      "x": -0.668378,
      "y": 2.095016,
      "theta": -0.07046
    },
    {
      "x": -0.756519,
      "y": 1.128844,
      "theta": 3.051202
    },
    {
      "x": -1.890541,
      "y": 0.893104,
      "theta": 2.81765
    },
    {
      "x": -2.282652,
      "y": -0.113596,
      "theta": 5.216489
    },
    {
      "x": -1.457368,
      "y": -1.437039,
      "theta": 4.375469
    },
    {
      "x": -0.395035,
      "y": -1.928913,
      "theta": 5.302784
    },
    {
      "x": 0.61555,
      "y": -2.364379,
      "theta": 5.461087
    },
    {
      "x": 1.620403,
      "y": -0.689314,
      "theta": 4.241945
    },
    {
      "x": 1.241739,
      "y": -0.487201,
      "theta": 7.380975
    },
    {
      "x": 0.364892,
      "y": 0.382604,
      "theta": 8.016195
    },
    {
      "x": -0.384364,
      "y": -0.753314,
      "theta": 9.301581
    },
    {
      "x": -0.379408,
      "y": -0.7137,
      "theta": 12.44322
    }
  ]
}
