Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enh] Add numpy solver in config solvers #869

Merged
Merged
Show file tree
Hide file tree
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
14 changes: 0 additions & 14 deletions examples/NLS-MB/NLS-MB_optical_rogue_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,6 @@ def inference(cfg: DictConfig):
store_key: output_dict[infer_key]
for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys())
}
# TODO: Fix this mapping diff in dy2st
(
output_dict["Eu"],
output_dict["Ev"],
output_dict["eta"],
output_dict["pu"],
output_dict["pv"],
) = (
output_dict["Eu"],
output_dict["Ev"],
output_dict["pu"],
output_dict["pv"],
output_dict["eta"],
)

# visualize prediction
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(input_dict)
Expand Down
14 changes: 0 additions & 14 deletions examples/NLS-MB/NLS-MB_optical_soliton.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,20 +394,6 @@ def inference(cfg: DictConfig):
store_key: output_dict[infer_key]
for store_key, infer_key in zip(cfg.MODEL.output_keys, output_dict.keys())
}
# TODO: Fix this mapping diff in dy2st
(
output_dict["Eu"],
output_dict["Ev"],
output_dict["eta"],
output_dict["pu"],
output_dict["pv"],
) = (
output_dict["Eu"],
output_dict["Ev"],
output_dict["pu"],
output_dict["pv"],
output_dict["eta"],
)

# visualize prediction
Eu_true, Ev_true, pu_true, pv_true, eta_true = analytic_solution(input_dict)
Expand Down
13 changes: 13 additions & 0 deletions ppsci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@
"run_check_mesh",
"lambdify",
]


# NOTE: Register custom solvers for parsing values from omegaconf more flexible
def _register_config_solvers():
import numpy as np
from omegaconf import OmegaConf

# register solver for "${numpy: xxx}" item, e.g. pi: "${numpy: pi}"
if not OmegaConf.has_resolver("numpy"):
OmegaConf.register_new_resolver("numpy", lambda x: getattr(np, x))


_register_config_solvers()