Skip to content

Commit

Permalink
Merge branch 'fix-modelrunner-inputs' of github.com:Noble-Lab/casanov…
Browse files Browse the repository at this point in the history
…o into fix-modelrunner-inputs
  • Loading branch information
bittremieux committed Dec 12, 2023
2 parents 05adba6 + 9a1df46 commit 8c88a71
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 373 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install your custom tools
run: pip install .
run: |
python -m pip install --upgrade pip
pip install .
- name: Generate terminal images with rich-codex
uses: ewels/rich-codex@v1
Expand Down
25 changes: 14 additions & 11 deletions casanovo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,20 @@ def __init__(self, config_file: Optional[str] = None):
else:
with Path(config_file).open() as f_in:
self._user_config = yaml.safe_load(f_in)
# check for missing entries in config file
if len(self._user_config.keys()) < len(self._params.keys()):
keys_set = set(self._params.keys())
users_set = set(self._user_config.keys())
missing = list(keys_set - users_set)
raise KeyError(f"Missing expected entry {missing}")
# detect unrecognized config file entries
keys = list(self._params.keys())
for key, val in self._user_config.items():
if key not in keys:
raise KeyError(f"Unrecognized config file entry {key}")
# Check for missing entries in config file.
config_missing = self._params.keys() - self._user_config.keys()
if len(config_missing) > 0:
raise KeyError(
"Missing expected config option(s): "
f"{', '.join(config_missing)}"
)
# Check for unrecognized config file entries.
config_unknown = self._user_config.keys() - self._params.keys()
if len(config_unknown) > 0:
raise KeyError(
"Unrecognized config option(s): "
f"{', '.join(config_unknown)}"
)
# Validate:
for key, val in self._config_types.items():
self.validate_param(key, val)
Expand Down
69 changes: 35 additions & 34 deletions docs/images/configure-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 66 additions & 65 deletions docs/images/evaluate-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
163 changes: 82 additions & 81 deletions docs/images/help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
131 changes: 66 additions & 65 deletions docs/images/sequence-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
183 changes: 92 additions & 91 deletions docs/images/train-help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 21 additions & 23 deletions tests/unit_tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Test configuration loading"""
from casanovo.config import Config
import pytest
import yaml

from casanovo.config import Config


def test_default():
"""Test that loading the default works"""
Expand All @@ -14,27 +15,24 @@ def test_default():


def test_override(tmp_path, tiny_config):
"""Test overriding the default"""
yml = tmp_path / "test.yml"
with yml.open("w+") as f_out:
f_out.write(
"""random_seed: 42
top_match: 3
residues:
W: 1
O: 2
U: 3
T: 4
"""
)

with open(tiny_config, "r") as read_file:
contents = yaml.safe_load(read_file)
contents["random_seed_"] = 354

with open("output.yml", "w") as write_file:
yaml.safe_dump(contents, write_file)
# Test expected config option is missing.
filename = str(tmp_path / "config_missing.yml")
with open(tiny_config, "r") as f_in, open(filename, "w") as f_out:
cfg = yaml.safe_load(f_in)
# Remove config option.
del cfg["random_seed"]
yaml.safe_dump(cfg, f_out)

with pytest.raises(KeyError):
config = Config("output.yml")
Config(filename)

# Test invalid config option is present.
filename = str(tmp_path / "config_invalid.yml")
with open(tiny_config, "r") as f_in, open(filename, "w") as f_out:
cfg = yaml.safe_load(f_in)
# Insert invalid config option.
cfg["random_seed_"] = 354
yaml.safe_dump(cfg, f_out)

with pytest.raises(KeyError):
config = Config(yml)
Config(filename)

0 comments on commit 8c88a71

Please sign in to comment.