Skip to content

Commit

Permalink
Update inspect.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AnushkaShreyam authored Oct 17, 2024
1 parent 19ca98c commit ca885ce
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ersilia/publish/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,22 @@ def check_dependencies_are_valid(self):
return Result(True, "Check passed.")
return Result(False, details)


def check_comptuational_performance(self):
"""
Measure computational performance by serving the model and running predictions.
Includes tracking metrics using the --track flag.
Returns:
Returns:
Result: A namedtuple containing a boolean success status and details of the check.
"""
details = ""

for n in (1, 10, 100):

cmd = (
f"ersilia serve {self.model} && "
f"ersilia example -f my_input.csv -n {n} && "
"ersilia run -i my_input.csv && "
"ersilia run -i my_input.csv --track && " # Added --track flag
"ersilia close"
)

Expand All @@ -295,6 +296,16 @@ def check_comptuational_performance(self):
executionTime = endTime - startTime
details += f"Execution time ({n} Prediction(s)): {executionTime} seconds. "

# Try to read and analyze tracking data
try:
tracking_file = sorted(self.root.joinpath('.ersilia/tracking').glob('*.json'))[-1]
with open(tracking_file) as f:
tracking_data = json.load(f)
details += f"Memory usage ({n} predictions): {tracking_data.get('memory_percent', 'N/A')}%. "
details += f"CPU usage ({n} predictions): {tracking_data.get('cpu_percent', 'N/A')}%. "
except (IndexError, FileNotFoundError, json.JSONDecodeError) as e:
details += f"Warning: Could not read tracking data for {n} predictions. "

return Result(True, details)

def check_no_extra_files(self):
Expand Down

0 comments on commit ca885ce

Please sign in to comment.