|
|
@ -13,7 +13,9 @@ class Plan: |
|
|
|
self.pending_instances = [] |
|
|
|
self.assigned_instances = [] |
|
|
|
self.instance_states = {} |
|
|
|
|
|
|
|
|
|
|
|
self.__instance_id_counter = 0 |
|
|
|
|
|
|
|
self.__lock = threading.Lock() if lock == None else lock |
|
|
|
|
|
|
|
if experiment: |
|
|
@ -44,7 +46,7 @@ class Plan: |
|
|
|
with open(self.experiment, "r") as expf: |
|
|
|
exp_obj = json.loads(expf.read()) |
|
|
|
|
|
|
|
instances = batch.load(pl.Path(exp_obj["batch"]).resolve()) |
|
|
|
instances = batch.load(pl.Path(exp_obj["batch"])) |
|
|
|
|
|
|
|
if iterations_left == None: |
|
|
|
if "iterations" in exp_obj: |
|
|
@ -57,7 +59,7 @@ class Plan: |
|
|
|
content["iterations_left"] = iterations_left |
|
|
|
|
|
|
|
return content |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __set_file(self): |
|
|
|
if self.experiment == None: |
|
|
@ -78,6 +80,8 @@ class Plan: |
|
|
|
|
|
|
|
if "assigned" in content: |
|
|
|
self.assigned_instances = content["assigned"] |
|
|
|
|
|
|
|
self.__instance_id_counter = max(map(lambda i: i["id"], self.assigned_instances)) + 1 |
|
|
|
|
|
|
|
if "pending" in content: |
|
|
|
self.pending_instances = content["pending"] |
|
|
@ -105,6 +109,9 @@ class Plan: |
|
|
|
return None |
|
|
|
|
|
|
|
next_instance = self.pending_instances.pop() |
|
|
|
next_instance["id"] = self.__instance_id_counter |
|
|
|
self.__instance_id_counter += 1 |
|
|
|
|
|
|
|
self.assigned_instances.append(next_instance) |
|
|
|
|
|
|
|
self.__update_file() |
|
|
@ -116,11 +123,11 @@ class Plan: |
|
|
|
with self.__lock: |
|
|
|
self.__load() |
|
|
|
|
|
|
|
if instance in self.assigned_instances: |
|
|
|
self.assigned_instances.remove(instance) |
|
|
|
self.assigned_instances = list(filter(lambda i: i["id"] != instance["id"], |
|
|
|
self.assigned_instances )) |
|
|
|
|
|
|
|
if instance in self.instance_states: |
|
|
|
self.instance_states.pop(instance) |
|
|
|
if str(instance["id"]) in self.instance_states: |
|
|
|
self.instance_states.pop(str(instance["id"])) |
|
|
|
|
|
|
|
self.__update_file() |
|
|
|
|
|
|
@ -158,11 +165,6 @@ class Plan: |
|
|
|
self.__write_content(content) |
|
|
|
|
|
|
|
def __write_content(self, content): |
|
|
|
if "assigned" in content: |
|
|
|
content["assigned"][:] = map(str, content["assigned"]) |
|
|
|
|
|
|
|
if "pending" in content: |
|
|
|
content["pending"][:] = map(str, content["pending"]) |
|
|
|
|
|
|
|
with open(self.file, "w") as pfile: |
|
|
|
pfile.write(json.dumps(content)) |
|
|
@ -172,7 +174,7 @@ class Plan: |
|
|
|
with self.__lock: |
|
|
|
self.__load() |
|
|
|
|
|
|
|
self.instance_states[instance] = data |
|
|
|
self.instance_states[str(instance["id"])] = data |
|
|
|
|
|
|
|
self.__update_file() |
|
|
|
|
|
|
@ -181,8 +183,8 @@ class Plan: |
|
|
|
with self.__lock: |
|
|
|
self.__load() |
|
|
|
|
|
|
|
if instance in self.instance_states: |
|
|
|
return self.instance_states[instance] |
|
|
|
if str(instance["id"]) in self.instance_states: |
|
|
|
return self.instance_states[str(instance["id"])] |
|
|
|
else: |
|
|
|
return "" |
|
|
|
|
|
|
|