Skip to content

Commit

Permalink
Rename collection and related texts from "labels" to "job user props".
Browse files Browse the repository at this point in the history
  • Loading branch information
notoraptor committed Feb 29, 2024
1 parent f3b2619 commit 48adaa3
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 104 deletions.
8 changes: 4 additions & 4 deletions clockwork_web/browser_routes/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def route_search():
- "sort_asc" is an optional integer and used to specify if sorting is
ascending (1) or descending (-1). Default is 1.
- "job_array" is optional and used to specify the job array in which we are looking for jobs
- "job_label_name" is optional and used to specify the label name associated to jobs we are looking for
- "job_label_content" is optional and used to specify the label value associated to jobs we are looking for
- "user_prop_name" is optional and used to specify the user prop name associated to jobs we are looking for
- "user_prop_content" is optional and used to specify the user prop value associated to jobs we are looking for
.. :quickref: list all Slurm job as formatted html
"""
Expand Down Expand Up @@ -166,8 +166,8 @@ def route_search():
"sort_by": query.sort_by,
"sort_asc": query.sort_asc,
"job_array": query.job_array,
"job_label_name": query.job_label_name,
"job_label_content": query.job_label_content,
"user_prop_name": query.user_prop_name,
"user_prop_content": query.user_prop_content,
},
)

Expand Down
71 changes: 37 additions & 34 deletions clockwork_web/core/jobs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,41 +158,44 @@ def get_filtered_and_paginated_jobs(
# on the server because not enough memory was allocated to perform the sorting.
LD_jobs = list(mc["jobs"].find(mongodb_filter))

# Get job labels
# Get job user props
if LD_jobs:
label_map = {}
# Collect all labels related to found jobs,
# and store them in a dict with keys (user ID, job ID, cluster_name)
for label in list(
mc["labels"].find(
user_props_map = {}
# Collect all job user props related to found jobs,
# and store them in a dict with keys (mila email username, job ID, cluster_name)
for user_props in list(
mc["job_user_props"].find(
combine_all_mongodb_filters(
{
"job_id": {
"$in": [int(job["slurm"]["job_id"]) for job in LD_jobs]
},
"user_id": current_user.mila_email_username,
"mila_email_username": current_user.mila_email_username,
}
)
)
):
# Remove MongoDB identifier, as we won't use it.
label.pop("_id")
key = (label["user_id"], label["job_id"], label["cluster_name"])
assert key not in label_map
label_map[key] = label["labels"]

if label_map:
# Populate jobs with labels using job's user email, job ID and cluster name
# to find related labels in labels dict.
key = (
user_props["mila_email_username"],
user_props["job_id"],
user_props["cluster_name"],
)
assert key not in user_props_map
user_props_map[key] = user_props["props"]

if user_props_map:
# Populate jobs with user props using
# current user email, job ID and job cluster name
# to find related user props in props map.
for job in LD_jobs:
key = (
# job["cw"]["mila_email_username"],
current_user.mila_email_username,
int(job["slurm"]["job_id"]),
job["slurm"]["cluster_name"],
)
if key in label_map:
job["job_labels"] = label_map[key]
if key in user_props_map:
job["job_user_props"] = user_props_map[key]

# Set nbr_total_jobs
if want_count:
Expand Down Expand Up @@ -272,8 +275,8 @@ def get_jobs(
sort_by="submit_time",
sort_asc=-1,
job_array=None,
job_label_name=None,
job_label_content=None,
user_prop_name=None,
user_prop_content=None,
):
"""
Set up the filters according to the parameters and retrieve the requested jobs from the database.
Expand All @@ -291,33 +294,33 @@ def get_jobs(
sort_asc Whether or not to sort in ascending order (1)
or descending order (-1).
job_array ID of job array in which we look for jobs.
job_label_name name of label (string) we must find in jobs to look for.
job_label_content content of label (string) we must find in jobs to look for.
user_prop_name name of user prop (string) we must find in jobs to look for.
user_prop_content content of user prop (string) we must find in jobs to look for.
Returns:
A tuple containing:
- the list of jobs as first entity
- the total number of jobs corresponding of the filters in the databse, if want_count has been set to
True, None otherwise, as second element
"""
# If job label is specified,
# get job indices from jobs associated to this label.
if job_label_name is not None and job_label_content is not None:
# If job user prop is specified,
# get job indices from jobs associated to this prop.
if user_prop_name is not None and user_prop_content is not None:
mc = get_db()
label_job_ids = [
str(label["job_id"])
for label in mc["labels"].find(
props_job_ids = [
str(user_props["job_id"])
for user_props in mc["job_user_props"].find(
combine_all_mongodb_filters(
{f"labels.{job_label_name}": job_label_content}
{f"props.{user_prop_name}": user_prop_content}
)
)
]
if job_ids:
# If job ids where provided, make intersection between given job ids and labelled job ids.
job_ids = list(set(label_job_ids) & set(job_ids))
# If job ids where provided, make intersection between given job ids and props job ids.
job_ids = list(set(props_job_ids) & set(job_ids))
else:
# Otherwise, just use labelled job ids.
job_ids = label_job_ids
# Otherwise, just use props job ids.
job_ids = props_job_ids

# Set up and combine filters
filter = get_global_filter(
Expand Down Expand Up @@ -464,7 +467,7 @@ def get_jobs_properties_list_per_page():
"user",
"job_id",
"job_array",
"job_labels",
"job_user_props",
"job_name",
"job_state",
"start_time",
Expand Down
12 changes: 6 additions & 6 deletions clockwork_web/core/search_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def parse_search_request(user, args, force_pagination=True):
want_count = to_boolean(want_count)

job_array = args.get("job_array", type=int, default=None)
job_label_name = args.get("job_label_name", type=str, default=None) or None
job_label_content = args.get("job_label_content", type=str, default=None) or None
user_prop_name = args.get("user_prop_name", type=str, default=None) or None
user_prop_content = args.get("user_prop_content", type=str, default=None) or None

default_page_number = "1" if force_pagination else None

Expand Down Expand Up @@ -73,8 +73,8 @@ def parse_search_request(user, args, force_pagination=True):
sort_asc=sort_asc,
want_count=want_count,
job_array=job_array,
job_label_name=job_label_name,
job_label_content=job_label_content,
user_prop_name=user_prop_name,
user_prop_content=user_prop_content,
)

#########################
Expand Down Expand Up @@ -119,7 +119,7 @@ def search_request(user, args, force_pagination=True):
sort_by=query.sort_by,
sort_asc=query.sort_asc,
job_array=query.job_array,
job_label_name=query.job_label_name,
job_label_content=query.job_label_content,
user_prop_name=query.user_prop_name,
user_prop_content=query.user_prop_content,
)
return (query, jobs, nbr_total_jobs)
14 changes: 7 additions & 7 deletions clockwork_web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,11 @@ <h1><a data-bs-toggle="collapse" data-bs-target=".formCollapse" aria-expanded="f
{% if previous_request_args['job_array'] is not none %}
<input type="hidden" name="job_array" value="{{ previous_request_args['job_array'] }}"/>
{% endif %}
{% if previous_request_args['job_label_name'] is not none %}
<input type="hidden" name="job_label_name" value="{{ previous_request_args['job_label_name'] }}"/>
{% if previous_request_args['user_prop_name'] is not none %}
<input type="hidden" name="user_prop_name" value="{{ previous_request_args['user_prop_name'] }}"/>
{% endif %}
{% if previous_request_args['job_label_content'] is not none %}
<input type="hidden" name="job_label_content" value="{{ previous_request_args['job_label_content'] }}"/>
{% if previous_request_args['user_prop_content'] is not none %}
<input type="hidden" name="user_prop_content" value="{{ previous_request_args['user_prop_content'] }}"/>
{% endif %}

<div class="row align-items-center">
Expand All @@ -341,9 +341,9 @@ <h1><a data-bs-toggle="collapse" data-bs-target=".formCollapse" aria-expanded="f
</a>
{% endif %}

{% if previous_request_args['job_label_name'] is not none and previous_request_args['job_label_content'] is not none %}
<a href="{{ modify_query(job_label_name='', job_label_content='') }}" title="Reset filter by job label" class="px-3 py-2">
Label <strong>{{ previous_request_args['job_label_name'] }}</strong>: "{{ previous_request_args['job_label_content'] }}"&nbsp;&nbsp;&nbsp;&nbsp;
{% if previous_request_args['user_prop_name'] is not none and previous_request_args['user_prop_content'] is not none %}
<a href="{{ modify_query(user_prop_name='', user_prop_content='') }}" title="Reset filter by job user prop" class="px-3 py-2">
User prop <strong>{{ previous_request_args['user_prop_name'] }}</strong>: "{{ previous_request_args['user_prop_content'] }}"&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fa-solid fa-circle-xmark" style="color: #888a85;"></i>
</a>
{% endif %}
Expand Down
18 changes: 9 additions & 9 deletions clockwork_web/templates/jobs_search.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ <h1>JOBS</h1>
{% if (web_settings | check_web_settings_column_display(page_name, "job_array")) %}
<th>Job array</th>
{% endif %}
<!-- Job labels header -->
{% if (web_settings | check_web_settings_column_display(page_name, "job_labels")) %}
<th>labels</th>
<!-- Job user props header -->
{% if (web_settings | check_web_settings_column_display(page_name, "job_user_props")) %}
<th>Job-user props</th>
{% endif %}
<!-- Job name header -->
{% if (web_settings | check_web_settings_column_display(page_name, "job_name")) %}
Expand Down Expand Up @@ -197,14 +197,14 @@ <h1>JOBS</h1>
</td>
{% endif %}

<!-- Job labels -->
{% if (web_settings | check_web_settings_column_display(page_name, "job_labels")) %}
<!-- Job user props -->
{% if (web_settings | check_web_settings_column_display(page_name, "job_user_props")) %}
<td>
{% for D_label_name, D_label_content in D_job.get('job_labels', {}).items() %}
{% for D_user_prop_name, D_user_prop_content in D_job.get('job_user_props', {}).items() %}
<p>
<a href="{{ modify_query(job_label_name=D_label_name, job_label_content=D_label_content, page_num=1) }}" title="Filter by job label &quot;{{D_label_name}}&quot;: &quot;{{D_label_content}}&quot;">
<strong>{{ D_label_name }}</strong><br/>
{{ D_label_content }}
<a href="{{ modify_query(user_prop_name=D_user_prop_name, user_prop_content=D_user_prop_content, page_num=1) }}" title="Filter by job-user prop &quot;{{D_user_prop_name}}&quot;: &quot;{{D_user_prop_content}}&quot;">
<strong>{{ D_user_prop_name }}</strong><br/>
{{ D_user_prop_content }}
</a>
</p>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions clockwork_web/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ <h1>{{ gettext("User settings %(mila_email_username)s", mila_email_username=curr
<th>{{ gettext("User (@mila.quebec)") }}</th>
<th>{{ gettext("Job ID") }}</th>
<th>{{ gettext("Job array") }}</th>
<th>{{ gettext("Job labels") }}</th>
<th>{{ gettext("Job-user props") }}</th>
<th>{{ gettext("Job name [:20]") }}</th>
<th>{{ gettext("Job state") }}</th>
<th>{{ gettext("Submit time") }}</th>
Expand All @@ -292,7 +292,7 @@ <h1>{{ gettext("User settings %(mila_email_username)s", mila_email_username=curr
<tbody>
<tr>
{% set page_name = "jobs_list" %}
{% for column_name in ["clusters", "user","job_id", "job_array", "job_labels", "job_name", "job_state", "submit_time", "start_time", "end_time", "links"] %}
{% for column_name in ["clusters", "user","job_id", "job_array", "job_user_props", "job_name", "job_state", "submit_time", "start_time", "end_time", "links"] %}
<td><div class="form-check form-switch">
{% if (web_settings | check_web_settings_column_display(page_name, column_name)) %}
<input name="{{page_name}}_{{column_name}}_toggle" id="{{page_name}}_{{column_name}}_toggle" type="checkbox" class="form-check-input" onclick="switch_column_setting('{{page_name}}', '{{column_name}}')" checked />
Expand Down
18 changes: 10 additions & 8 deletions scripts/store_huge_fake_data_in_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,15 @@ def _generate_huge_fake_data(
jobs.append({"slurm": job_slurm, "cw": job_cw, "user": {}})

# populate job-user-dicts
props_editor = "[email protected]" if nb_student_jobs else "[email protected]"
props_editor = (
"[email protected]" if nb_student_jobs else "[email protected]"
)
job_user_dicts = [
{
"user_id": props_editor,
"mila_email_username": props_editor,
"job_id": i + 1,
"cluster_name": "beluga",
"labels": {
"props": {
f"prop_{j + 1}_for_job_{i + 1}": f"I am user dict prop {j + 1} for job ID {i + 1}"
for j in range(nb_props_per_dict)
},
Expand All @@ -440,7 +442,7 @@ def _generate_huge_fake_data(
print(
f"Jobs: {len(jobs)}, dicts: {len(job_user_dicts)}, props per dict: {nb_props_per_dict}"
)
return {"users": USERS, "jobs": jobs, "labels": job_user_dicts}
return {"users": USERS, "jobs": jobs, "job_user_props": job_user_dicts}


def populate_fake_data(db_insertion_point, **kwargs):
Expand All @@ -463,12 +465,12 @@ def populate_fake_data(db_insertion_point, **kwargs):
[("mila_email_username", 1)], name="users_email_index"
)
db_insertion_point["gpu"].create_index([("name", 1)], name="gpu_name")
db_insertion_point["labels"].create_index(
[("user_id", 1), ("job_id", 1), ("cluster_name", 1), ("labels", 1)],
name="job_label_index",
db_insertion_point["job_user_props"].create_index(
[("mila_email_username", 1), ("job_id", 1), ("cluster_name", 1), ("props", 1)],
name="job_user_props_index",
)

for k in ["users", "jobs", "nodes", "gpu", "labels"]:
for k in ["users", "jobs", "nodes", "gpu", "job_user_props"]:
# Anyway clean before inserting
db_insertion_point[k].delete_many({})
if k in E and E[k]:
Expand Down
34 changes: 17 additions & 17 deletions test_common/fake_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -5963,46 +5963,46 @@
"tflops_fp32": 16.31
}
],
"labels": [
"job_user_props": [
{
"user_id": "student06@mila.quebec",
"mila_email_username": "student00@mila.quebec",
"job_id": 795002,
"cluster_name": "mila",
"labels": {
"name": "je suis un label 1"
"props": {
"name": "je suis une user prop 1"
}
},
{
"user_id": "student16@mila.quebec",
"mila_email_username": "student00@mila.quebec",
"job_id": 606872,
"cluster_name": "mila",
"labels": {
"name": "je suis un label 2"
"props": {
"name": "je suis une user prop 2"
}
},
{
"user_id": "student15@mila.quebec",
"mila_email_username": "student00@mila.quebec",
"job_id": 834395,
"cluster_name": "graham",
"labels": {
"name": "je suis un label 3"
"props": {
"name": "je suis une user prop 3"
}
},
{
"user_id": "student15@mila.quebec",
"mila_email_username": "student00@mila.quebec",
"job_id": 154325,
"cluster_name": "graham",
"labels": {
"name": "je suis un label 3",
"name2": "je suis un label 4"
"props": {
"name": "je suis une user prop 3",
"name2": "je suis une user prop 4"
}
},
{
"user_id": "student12@mila.quebec",
"mila_email_username": "student00@mila.quebec",
"job_id": 613024,
"cluster_name": "graham",
"labels": {
"name": "je suis un label 1"
"props": {
"name": "je suis une user prop 1"
}
}
]
Expand Down
Loading

0 comments on commit 48adaa3

Please sign in to comment.