Skip to content

Commit

Permalink
fix models/voronoi/featurize_mp_wbm.py featurizer.set_n_jobs(1)
Browse files Browse the repository at this point in the history
wandb.log features as wandb.Table
  • Loading branch information
janosh committed Jun 20, 2023
1 parent 8acba18 commit 8508c38
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions models/bowsr/test_bowsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@

# %%
slurm_array_task_id = int(os.environ.get("SLURM_ARRAY_TASK_ID", 0))
out_path = f"{out_dir}/{slurm_array_task_id}.json.gz"
out_path = f"{out_dir}/bowsr-preds-{slurm_array_task_id}.json.gz"

print(f"Job started running {timestamp}")
print(f"\nJob started running {timestamp}")
print(f"{data_path = }")
print(f"{out_path = }")
print(f"{version('maml') = }")
Expand Down
2 changes: 1 addition & 1 deletion models/cgcnn/train_cgcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@


# %%
print(f"Job started running {timestamp}")
print(f"\nJob started running {timestamp}")

train_model(
checkpoint="wandb", # None | 'local' | 'wandb',
Expand Down
4 changes: 2 additions & 2 deletions models/m3gnet/test_m3gnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
# %%
slurm_array_task_id = int(os.environ.get("SLURM_ARRAY_TASK_ID", 0))

print(f"Job started running {timestamp}")
print(f"\nJob started running {timestamp}")
print(f"{version('m3gnet') = }")

out_path = f"{out_dir}/{slurm_array_task_id}.json.gz"
out_path = f"{out_dir}/m3gnet-preds-{slurm_array_task_id}.json.gz"

if os.path.isfile(out_path):
raise SystemExit(f"{out_path = } already exists, exciting early")
Expand Down
5 changes: 2 additions & 3 deletions models/megnet/test_megnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


# %%
print(f"Job started running {timestamp}")
print(f"\nJob started running {timestamp}")

out_path = f"{out_dir}/megnet-e-form-preds.csv"
if os.path.isfile(out_path):
Expand All @@ -56,7 +56,6 @@
print(f"Loading from {data_path=}")
df_wbm_structs = pd.read_json(data_path).set_index("material_id")


megnet_mp_e_form = load_model(model_name := "Eform_MP_2019")


Expand Down Expand Up @@ -109,7 +108,7 @@
out_col = "e_form_per_atom_megnet"
df_wbm[out_col] = pd.Series(megnet_e_form_preds)

df_wbm[out_col].reset_index().to_csv(out_path)
df_wbm[out_col].reset_index().to_csv(out_path, index=False)


# %%
Expand Down
27 changes: 17 additions & 10 deletions models/voronoi/featurize_mp_wbm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,29 @@
data_path = f"{ROOT}/data/wbm/2022-10-19-wbm-init-structs.json.bz2"
input_col = "initial_structure"
data_name = "wbm" if "wbm" in data_path else "mp"
slurm_array_task_count = 20
job_name = f"voronoi-featurize-{data_name}"
slurm_array_task_count = 10
job_name = f"voronoi-features-{data_name}"
log_dir = f"{module_dir}/{today}-{job_name}"

slurm_vars = slurm_submit(
job_name=job_name,
partition="icelake-himem",
account="LEE-SL3-CPU",
time=(slurm_max_job_time := "5:0:0"),
array=f"1-{slurm_array_task_count}",
log_dir=f"{module_dir}/{job_name}",
log_dir=log_dir,
)


# %%
df = pd.read_json(data_path).set_index("material_id")

slurm_array_task_id = int(os.environ.get("SLURM_ARRAY_TASK_ID", 0))
run_name = f"{job_name}-{slurm_array_task_id}"
out_path = f"{log_dir}/{run_name}.csv.bz2"

if os.path.isfile(out_path):
raise SystemExit(f"{out_path = } already exists, exciting early")

df = pd.read_json(data_path).set_index("material_id")
df_this_job: pd.DataFrame = np.array_split(df, slurm_array_task_count)[
slurm_array_task_id - 1
]
Expand Down Expand Up @@ -90,18 +94,21 @@
feat_struct.StructureComposition(feat_comp.IonProperty(fast=True)),
]
featurizer = MultipleFeaturizer(featurizers)
# multiprocessing seems to be the cause of OOM errors on large structures even when
# taking only small slice of the data and launching slurm jobs with --mem 100G
featurizer.set_n_jobs(1)


# %% prints lots of pymatgen warnings
# > No electronegativity for Ne. Setting to NaN. This has no physical meaning, ...
warnings.filterwarnings(action="ignore", category=UserWarning, module="pymatgen")

df_features = featurizer.featurize_dataframe(
df_this_job, input_col, ignore_errors=True, pbar=True
)
df_this_job, input_col, ignore_errors=True, pbar=dict(position=0, leave=True)
).drop(columns=input_col)


# %%
df_features.to_json(
f"{module_dir}/{today}-{run_name}.json.gz", default_handler=as_dict_handler
)
df_features.to_csv(out_path, default_handler=as_dict_handler)

wandb.log({"voronoi_features": wandb.Table(dataframe=df_features)})
2 changes: 1 addition & 1 deletion models/wrenformer/train_wrenformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
slurm_array_task_id = int(os.environ.get("SLURM_ARRAY_TASK_ID", 0))
input_col = "wyckoff_spglib"

print(f"Job started running {timestamp}")
print(f"\nJob started running {timestamp}")
print(f"{run_name=}")
print(f"{data_path=}")

Expand Down

0 comments on commit 8508c38

Please sign in to comment.