Beispiel #1
0
def test_load_referenced_json_config(config, string_formatting_dict, expected):
    recursively_update_config(config, string_formatting_dict)

    assert config == expected
Beispiel #2
0
# ```python
# >>> config = {"some_value": "some_string_{some_placeholder}"}
# >>> string_formatting_dict = {"some_placeholder": "ABC"}
# >>> utils.recursively_update_config(config, string_formatting_dict)
# >>> print(config)
# {"some_value": "some_string_ABC}"}
# ```
#
#

# First update `config["meta_info"]`

utils.recursively_update_config(
    config["meta_info"], {
        "evaluation_session_id": evaluation_session_id,
        "session_id": config["meta_info"]["session_id"],
        "model_purpose": config["meta_info"]["model_purpose"],
        "config_filepath": config_filepath,
        "notebook_filepath": notebook_filepath
    })

# Then use `config["meta_info"]` to update the rest.

utils.recursively_update_config(config, config["meta_info"])

# ## Session
#
# Create a small dictionary with the session information. This will later be stored as a dictionary artifact with all the key run infomration

evaluation_session = {
    "time_stamp": datetime.datetime.utcnow().isoformat()[:-3] + "Z",
    "run_by": getpass.getuser(),
Beispiel #3
0
# Although Mercury-ML does not require you to work with config files, it is encouraged as this allows you to make full
# use of the code abstraction capabilities that are on offer.

# We have included a few small utils that help with dealing with config files. In this example, we'll show how you can
# resolve string formatting within a config file

# Let's first try to read our JSON file using the json library:
# Note the following entries:
#     "model_object_name": "my_model_{model_id}.h5"
#     "filepath": "/some/path/{model_object_name}"
# The {...} values are placeholders for string formatting
import json
with open("./02_resolving_string_formatting_config.json", "r") as f:
    config = json.load(f)
print("Raw input: ")
print(json.dumps(config, indent=2), "\n")


# Now let's use mercury_ml.common.utils.recursively_update_config to replace the placeholders in config["meta_info"]
# with and actual value
from mercury_ml.common.utils import recursively_update_config
recursively_update_config(config["meta_info"], {"model_id": "abc_123"})
print("After updating meta_info: ")
print(json.dumps(config, indent=2), "\n")

# Lastly, let's use config["meta_info"] to update the rest of the config
recursively_update_config(config, config["meta_info"])
print("After updating the entire config: ")
print(json.dumps(config, indent=2), "\n")