Skip to content

Commit 940eb60

Browse files
DanielYang59janosh
andauthored
Fix Incar check_params for Union type (#3958)
* add test case for Union type LREAL * remove debug msg * update type check mechanism * use eval for type checking * use isinstance syntax * try to increase dependency palettable version * bump monty to 2024.7.29 * pin torch version until matgl release * Revert "pin torch version until matgl release" This reverts commit 215c888. * skip failing matgl tests for now --------- Signed-off-by: Janosh Riebesell <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent b35b99e commit 940eb60

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ classifiers = [
5757
dependencies = [
5858
"joblib>=1",
5959
"matplotlib>=3.8",
60-
"monty>=2024.5.24",
60+
"monty>=2024.7.29",
6161
"networkx>=2.2",
62-
"palettable>=3.1.1",
62+
'numpy>=1.25.0,<2.0 ; platform_system == "Windows"',
63+
'numpy>=1.25.0 ; platform_system != "Windows"',
64+
"palettable>=3.3.3",
6365
"pandas>=2",
6466
"plotly>=4.5.0",
6567
"pybtex>=0.24.0",

src/pymatgen/io/vasp/incar_parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@
650650
"type": "bool"
651651
},
652652
"LREAL": {
653-
"type": "Union[bool, str]",
653+
"type": "(bool, str)",
654654
"values": [
655655
false,
656656
true,

src/pymatgen/io/vasp/inputs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,10 +1028,10 @@ def check_params(self) -> None:
10281028
continue
10291029

10301030
# Check value and its type
1031-
param_type = incar_params[tag].get("type")
1032-
allowed_values = incar_params[tag].get("values")
1031+
param_type: str = incar_params[tag].get("type")
1032+
allowed_values: list[Any] = incar_params[tag].get("values")
10331033

1034-
if param_type is not None and type(val).__name__ != param_type:
1034+
if param_type is not None and not isinstance(val, eval(param_type)):
10351035
warnings.warn(f"{tag}: {val} is not a {param_type}", BadIncarWarning, stacklevel=2)
10361036

10371037
# Only check value when it's not None,

tests/core/test_structure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,7 @@ def test_relax_ase_opt_kwargs(self):
17691769
assert traj[0] != traj[-1]
17701770
assert os.path.isfile(traj_file)
17711771

1772+
@pytest.mark.skip("TODO: #3958 wait for matgl resolve of torch dependency")
17721773
def test_calculate_m3gnet(self):
17731774
pytest.importorskip("matgl")
17741775
calculator = self.get_structure("Si").calculate()
@@ -1780,6 +1781,7 @@ def test_calculate_m3gnet(self):
17801781
assert np.linalg.norm(calculator.results["forces"]) == approx(7.8123485e-06, abs=0.2)
17811782
assert np.linalg.norm(calculator.results["stress"]) == approx(1.7861567, abs=2)
17821783

1784+
@pytest.mark.skip("TODO: #3958 wait for matgl resolve of torch dependency")
17831785
def test_relax_m3gnet(self):
17841786
matgl = pytest.importorskip("matgl")
17851787
struct = self.get_structure("Si")
@@ -1790,6 +1792,7 @@ def test_relax_m3gnet(self):
17901792
actual = relaxed.dynamics[key]
17911793
assert actual == val, f"expected {key} to be {val}, {actual=}"
17921794

1795+
@pytest.mark.skip("TODO: #3958 wait for matgl resolve of torch dependency")
17931796
def test_relax_m3gnet_fixed_lattice(self):
17941797
matgl = pytest.importorskip("matgl")
17951798
struct = self.get_structure("Si")
@@ -1798,6 +1801,7 @@ def test_relax_m3gnet_fixed_lattice(self):
17981801
assert isinstance(relaxed.calc, matgl.ext.ase.M3GNetCalculator)
17991802
assert relaxed.dynamics["optimizer"] == "BFGS"
18001803

1804+
@pytest.mark.skip("TODO: #3958 wait for matgl resolve of torch dependency")
18011805
def test_relax_m3gnet_with_traj(self):
18021806
pytest.importorskip("matgl")
18031807
struct = self.get_structure("Si")

tests/io/vasp/test_inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ def test_check_params(self):
774774
"AMIN": 0.01,
775775
"ICHARG": 1,
776776
"MAGMOM": [1, 2, 4, 5],
777+
"LREAL": True, # special case: Union type
777778
"NBAND": 250, # typo in tag
778779
"METAGGA": "SCAM", # typo in value
779780
"EDIFF": 5 + 1j, # value should be a float

0 commit comments

Comments
 (0)