When setting up a mace_mp calculator by passing a local path as model, characters that are not alphanumeric characters or underscores are stripped from the model path, meaning that the model may not be found.
For example, a model /home/ek/.cache/mace/MACE-OFF23_small.model will be converted into /home/ek/.cache/mace/MACEOFF23_smallmodel, meaning that the file will not be found.
The directory of the model path is also automatically replaced with ~/.cache/mace. For example, /home/ek/PSDI/janus-core/MACE-OFF23_small.model is replaced with /home/ek/.cache/mace/MACEOFF23_smallmodel, limiting where models can be stored.
To Reproduce
Run
from mace.calculators import mace_mp
from pathlib import Path
model = Path("~/.cache/mace/MACE-OFF23_small.model").expanduser()
calculator = mace_mp(model=model)
This leads to an error
Downloading MACE model from PosixPath('/home/ek/.cache/mace/MACE-OFF23_small.model')
Traceback (most recent call last):
File "/home/ek/PSDI/venv_janus_11_new/lib/python3.11/site-packages/mace/calculators/foundations_models.py", line 104, in mace_mp
model_path = download_mace_mp_checkpoint(model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ek/PSDI/venv_janus_11_new/lib/python3.11/site-packages/mace/calculators/foundations_models.py", line 53, in download_mace_mp_checkpoint
_, http_msg = urllib.request.urlretrieve(checkpoint_url, cached_model_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/request.py", line 239, in urlretrieve
url_type, path = _splittype(url)
^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/urllib/parse.py", line 1070, in _splittype
match = _typeprog.match(url)
^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'PosixPath'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/ek/PSDI/janus-core/test_mace_mp.py", line 7, in <module>
calculator = mace_mp(model=model)
^^^^^^^^^^^^^^^^^^^^
File "/home/ek/PSDI/venv_janus_11_new/lib/python3.11/site-packages/mace/calculators/foundations_models.py", line 107, in mace_mp
raise RuntimeError("Model download failed and no local model found") from exc
RuntimeError: Model download failed and no local model found
Expected behavior
The correct model path specified should be used. In 0.3.6, the above code works, due to a check:
elif model in (None, "small", "medium", "large") or str(model).startswith("https:"):
which meant the equivalent code to download_mace_mp_checkpoint could be skipped.
Alternatively, mace_off does a slightly different character replacment:
Describe the bug
When setting up a
mace_mp
calculator by passing a local path asmodel
, characters that are not alphanumeric characters or underscores are stripped from the model path, meaning that the model may not be found.For example, a model
/home/ek/.cache/mace/MACE-OFF23_small.model
will be converted into/home/ek/.cache/mace/MACEOFF23_smallmodel
, meaning that the file will not be found.The directory of the model path is also automatically replaced with
~/.cache/mace
. For example,/home/ek/PSDI/janus-core/MACE-OFF23_small.model
is replaced with/home/ek/.cache/mace/MACEOFF23_smallmodel
, limiting where models can be stored.To Reproduce
This leads to an error
Expected behavior
The correct model path specified should be used. In 0.3.6, the above code works, due to a check:
which meant the equivalent code to
download_mace_mp_checkpoint
could be skipped.Alternatively,
mace_off
does a slightly different character replacment:which solves the problem of models with extensions, but still requires the model to be stored in
~/.cache/mace
, which seems unnecessary.Desktop (please complete the following information):