Skip to content

Commit

Permalink
refactor dict.update()
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Apr 26, 2024
1 parent daf5d46 commit 2b357d5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion fireworks/core/firework.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def _update_state_history(self, state) -> None:
now_time = datetime.utcnow()
new_history_entry = {"state": state, "created_on": now_time}
if state != "COMPLETED" and last_checkpoint:
new_history_entry.update({"checkpoint": last_checkpoint})
new_history_entry.update(checkpoint=last_checkpoint)
self.state_history.append(new_history_entry)
if state in ["RUNNING", "RESERVED"]:
self.touch_history() # add updated_on key
Expand Down
6 changes: 3 additions & 3 deletions fireworks/core/launchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def future_run_exists(self, fworker=None) -> bool:
return True
# retrieve all [RUNNING/RESERVED] fireworks
q = fworker.query if fworker else {}
q.update({"state": {"$in": ["RUNNING", "RESERVED"]}})
q.update(state={"$in": ["RUNNING", "RESERVED"]})
active = self.get_fw_ids(q)
# then check if they have WAITING children
for fw_id in active:
Expand Down Expand Up @@ -1670,7 +1670,7 @@ def rerun_fw(self, fw_id, rerun_duplicates=True, recover_launch=None, recover_mo
# Launch recovery
if recover_launch is not None:
recovery = self.get_recovery(fw_id, recover_launch)
recovery.update({"_mode": recover_mode})
recovery.update(_mode=recover_mode)
set_spec = recursive_dict({"$set": {"spec._recovery": recovery}})
if recover_mode == "prev_dir":
prev_dir = self.get_launch_by_id(recovery.get("_launch_id")).launch_dir
Expand Down Expand Up @@ -1714,7 +1714,7 @@ def get_recovery(self, fw_id, launch_id="last"):
m_fw = self.get_fw_by_id(fw_id)
launch = m_fw.launches[-1] if launch_id == "last" else self.get_launch_by_id(launch_id)
recovery = launch.state_history[-1].get("checkpoint")
recovery.update({"_prev_dir": launch.launch_dir, "_launch_id": launch.launch_id})
recovery.update(_prev_dir=launch.launch_dir, _launch_id=launch.launch_id)
return recovery

def _refresh_wf(self, fw_id) -> None:
Expand Down
10 changes: 5 additions & 5 deletions fireworks/features/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def group_fizzled_fireworks(
"created_on": self._query_datetime_range(start_time=query_start, end_time=query_end, **args),
}
if include_ids:
project_query.update({"fw_id": 1})
group_query.update({"fw_id": {"$push": "$fw_id"}})
project_query.update(fw_id=1)
group_query.update(fw_id={"$push": "$fw_id"})
if query:
match_query.update(query)
return self._aggregate(
Expand Down Expand Up @@ -306,11 +306,11 @@ def _get_summary(
}
match_query.update(query)
if runtime_stats:
project_query.update({"runtime_secs": 1})
project_query.update(runtime_secs=1)
group_query.update(RUNTIME_STATS)
if include_ids:
project_query.update({id_field: 1})
group_query.update({"ids": {"$push": "$" + id_field}})
group_query.update(ids={"$push": "$" + id_field})
return self._aggregate(
coll=coll,
match=match_query,
Expand Down Expand Up @@ -357,7 +357,7 @@ def _aggregate(
for arg in [match, project, unwind, group_op]:
if arg is None:
arg = {}
group_op.update({"_id": "$" + group_by})
group_op.update(_id=f"${group_by}")
if sort is None:
sort_query = ("_id", 1)
query = [{"$match": match}, {"$project": project}, {"$group": group_op}, {"$sort": SON([sort_query])}]
Expand Down
2 changes: 1 addition & 1 deletion fireworks/queue/queue_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def launch_rocket_to_queue(

# update qadapter job_name based on FW name
job_name = get_slug(fw.name)[0:QUEUE_JOBNAME_MAXLEN]
qadapter.update({"job_name": job_name})
qadapter.update(job_name=job_name)

if "_queueadapter" in fw.spec:
l_logger.debug("updating queue params using Firework spec..")
Expand Down
2 changes: 1 addition & 1 deletion fireworks/user_objects/queue_adapters/common_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, q_type, q_name=None, template_file=None, timeout=None, **kwar
)
self.q_name = q_name or q_type
self.timeout = timeout or 5
self.update(dict(kwargs))
self.update(kwargs)

self.q_commands = copy.deepcopy(CommonAdapter.default_q_commands)
if "_q_commands_override" in self:
Expand Down

0 comments on commit 2b357d5

Please sign in to comment.