Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Holden/track model runs using a file #15

Merged
merged 7 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ secrets.json
development.ipynb
development.py
tmp/
.idea/

# Sphinx related
/doctrees
Expand Down
10 changes: 10 additions & 0 deletions ersilia/cli/commands/close.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime
import os
from . import ersilia_cli
from .. import echo
from ... import ErsiliaModel
Expand All @@ -17,3 +19,11 @@ def close():
mdl = ErsiliaModel(model_id, service_class=service_class)
mdl.close()
echo(":no_entry: Model {0} closed".format(mdl.model_id), fg="green")

# renames current_session to timestamp
old_file_path = "current_session.txt"
new_file_path = os.path.join(
os.path.dirname(old_file_path),
datetime.datetime.now().strftime("%Y%m%d%H%M%S"),
)
os.rename(old_file_path, new_file_path)
13 changes: 12 additions & 1 deletion ersilia/cli/commands/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ def serve_cmd():
type=click.INT,
help="Preferred port to use (integer)",
)
def serve(model, lake, docker, port):
# Add the new flag for tracking the serve session
@click.option(
"-t/",
"--track_serve/--no_track_serve",
"track_serve",
required=False,
default=True,
)
def serve(model, lake, docker, port, track_serve):
if docker:
service_class = "docker"
else:
Expand Down Expand Up @@ -54,3 +62,6 @@ def serve(model, lake, docker, port):
echo("")
echo(":person_tipping_hand: Information:", fg="blue")
echo(" - info", fg="blue")
if track_serve:
with open("current_session.txt", "w") as f:
f.write("Session started for model: {0}".format(mdl.model_id))
12 changes: 11 additions & 1 deletion ersilia/core/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,19 @@ def track(self, input, result, meta):

self.get_file_sizes(input_dataframe, result_dataframe)

json_object = json.dumps(json_dict, indent = 4)
json_object = json.dumps(json_dict, indent=4)
print("\nJSON Dictionary:\n", json_object)

# log results to console
with open("../cli/commands/current_session.txt", "a") as f:
# write the print statements to a file
f.write(f"\n{json.dumps(input_dataframe)}\n")
f.write(f"\n{json.dumps(result_dataframe)}\n")
f.write(f"\n{json.dumps(meta)}\n")
f.write(f"\nModel ID: {model_id}\n")
f.write(f"\nTime taken: {time}\n")
f.write(f"\nNAN Count:\n {nan_count}\n")

def log_to_console(self, data):
print(f"\n{json.dumps(data)}\n")

Expand Down