SORILUN-RSI / research /src /context_policy.py
PureOne's picture
Add SORILUN research dataset release
aff9293 verified
Raw History Blame Contribute Delete
812 Bytes
"""Do not export a hardware promotion beyond its measured task context."""
from dataclasses import dataclass
import json
from pathlib import Path
@dataclass(frozen=True)
class ContextPolicy:
accepted: tuple
@classmethod
def from_gate(cls, path):
report=json.loads(Path(path).read_text())
items=[]
for event in report['records']:
if event['accepted']:
items.append(('reciprocal',int(event['length']),int(event['after_cap'])))
return cls(tuple(items))
def choose_cap(self,family,length):
if not isinstance(family,str) or not isinstance(length,int) or length<1:
raise ValueError('Invalid context')
matches=[cap for fam,n,cap in self.accepted if fam==family and n==length]
return max(matches,default=0)