Skip to content

Commit

Permalink
Track without output bug (#1170)
Browse files Browse the repository at this point in the history
* fixed errors that occurs when track is used without specifying an output

* moved the generator conversion outside the read_csv function into track

* resolving merge conflicts
  • Loading branch information
dzumii committed Jun 26, 2024
1 parent 9ace45e commit 116fd3c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions ersilia/core/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import logging
import requests
import tempfile
import types
import resource
import statistics
import tracemalloc
Expand Down Expand Up @@ -536,7 +537,27 @@ def track(self, input, result, meta):
self.docker_client = SimpleDocker()
json_dict = {}
input_data = read_csv(input)
result_data = read_csv(result)
# Create a temporary file to store the result if it is a generator
if isinstance(result, types.GeneratorType):

# Ensure EOS/tmp directory exists
tmp_dir = os.path.join(EOS, "tmp")
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir, exist_ok=True)

# Create a temporary file to store the generator output
temp_output_file = tempfile.NamedTemporaryFile(
delete=False, suffix=".csv", dir=tmp_dir
)
temp_output_path = temp_output_file.name
with open(temp_output_path, "w", newline="") as csvfile:
csvWriter = csv.writer(csvfile)
for row in result:
csvWriter.writerow(row)
result_data = read_csv(temp_output_path)
os.remove(temp_output_path)
else:
result_data = read_csv(result)

session = Session(config_json=self.config_json)
model_id = meta["metadata"].get("Identifier", "Unknown")
Expand Down Expand Up @@ -579,4 +600,4 @@ def track(self, input, result, meta):
def log(self, result, meta):
self.log_result(result)
self.log_meta(meta)
self.log_logs()
self.log_logs()

0 comments on commit 116fd3c

Please sign in to comment.