Skip to content
Draft
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
13 changes: 10 additions & 3 deletions mach_opt/mach_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def fitness(self, x: "tuple") -> "tuple":
# but make sure by joining it here
p.join()

# Apply transform to full_results (if needed)
if self.__dh.full_results_transform is not None:
full_results = self.__dh.full_results_transform(full_results)

objs = self.__design_space.get_objectives(full_results)
self.__dh.save_to_archive(x, design, full_results, objs)
# print('The fitness values are', objs)
Expand Down Expand Up @@ -278,9 +282,10 @@ def bounds(self) -> tuple:
class DataHandler():
""" Parent class for data handlers"""

def __init__(self, archive_filepath, designer_filepath):
def __init__(self, archive_filepath, designer_filepath, full_results_transform=None):
self.archive_filepath = archive_filepath
self.designer_filepath = designer_filepath
self.full_results_transform = full_results_transform

def save_to_archive(self, x, design, full_results, objs):
""" Save machine evaluation data to optimization archive using Pickle
Expand All @@ -291,9 +296,11 @@ def save_to_archive(self, x, design, full_results, objs):
full_results: Input, output, and results corresponding to each step of an evaluator
objs: Fitness values corresponding to a design
"""
# assign relevant data to OptiData class attributes

# Assign relevant data to OptiData class attributes
opti_data = OptiData(x=x, design=design, full_results=full_results, objs=objs)
# write to pkl file. 'ab' indicates binary append

# Write to pkl file. 'ab' indicates binary append
with open(self.archive_filepath, 'ab') as archive:
pickle.dump(opti_data, archive, -1)

Expand Down