55import subprocess
66import re
77from typing import Iterable , List , Optional
8- import numpy as np
98from pydantic import BaseModel , field_validator
109
11- from .constants import is_acceptable_method
1210from .method_context import MethodContext
1311
1412class SuperPmiContext (BaseModel ):
@@ -18,8 +16,7 @@ class SuperPmiContext(BaseModel):
1816 core_root : str
1917 mch : str
2018 jit : Optional [str ] = None
21- test_methods : Optional [List [int ]] = []
22- training_methods : Optional [List [int ]] = []
19+ methods : Optional [List [MethodContext ]] = []
2320
2421 @field_validator ('core_root' , 'mch' , mode = 'before' )
2522 @classmethod
@@ -37,37 +34,24 @@ def _validate_optional_path(cls, v):
3734
3835 return v
3936
40- def resplit_data (self , test_percent :float ):
41- """Splits the data into training and testing sets."""
42- if not self .test_methods and not self .training_methods :
43- raise ValueError ("No methods to split. Try calling 'find_methods_and_split' first." )
44-
45- all_methods = self .test_methods + self .training_methods
46- np .random .shuffle (all_methods )
47- self .test_methods = all_methods [:int (len (all_methods ) * test_percent )]
48- self .training_methods = all_methods [len (self .test_methods ):]
49-
50- def find_methods_and_split (self , test_percent :float ) -> None :
37+ @staticmethod
38+ def create_from_mch (mch : str , core_root : str , jit : Optional [str ] = None ) -> 'SuperPmiContext' :
5139 """Loads the SuperPmiContext from the specified arguments."""
52- suitable_methods = []
53- with SuperPmi (self ) as superpmi :
40+ result = SuperPmiContext (core_root = core_root , mch = mch , jit = jit )
41+
42+ methods = []
43+ with SuperPmi (result ) as superpmi :
5444 for method in superpmi .enumerate_methods ():
55- if is_acceptable_method (method ):
56- suitable_methods .append (method .index )
45+ methods .append (method )
5746
58- self . test_methods = suitable_methods
59- self . resplit_data ( test_percent )
47+ result . methods = methods
48+ return result
6049
6150 def save (self , file_path :str ):
6251 """Saves the SuperPmiContext to a file."""
6352 with open (file_path , 'w' , encoding = "utf8" ) as f :
6453 json .dump (self .model_dump (), f )
6554
66-
67- def create_superpmi (self , verbosity :str = 'q' ):
68- """Creates a SuperPmi object from this context."""
69- return SuperPmi (self , verbosity )
70-
7155 @staticmethod
7256 def load (file_path :str ):
7357 """Loads the SuperPmiContext from a file."""
@@ -78,13 +62,15 @@ def load(file_path:str):
7862 data = json .load (f )
7963 return SuperPmiContext (** data )
8064
65+ def create_superpmi (self , verbosity :str = 'q' ):
66+ """Creates a SuperPmi object from this context."""
67+ return SuperPmi (self , verbosity )
8168
8269class SuperPmi :
8370 """Controls one instance of superpmi."""
8471 def __init__ (self , context : SuperPmiContext , verbosity :str = 'q' ):
8572 """Constructor.
8673 core_root is the path to the coreclr build, usually at [repo]/artifiacts/bin/coreclr/[arch]/.
87- jit is the full path to the jit to use. Default is None.
8874 verbosity is the verbosity level of the superpmi process. Default is 'q'."""
8975 self ._process = None
9076 self ._feature_names = None
0 commit comments