File size: 812 Bytes
aff9293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
"""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)