From c7b2ae28dab6e107b19efbfe38f9cf7206385ad0 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 12:15:09 +0800 Subject: [PATCH 1/7] test monty fix for reverse readline --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70dc8cc7..9c95b1d8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,8 +34,8 @@ jobs: pip install uv uv pip install -e .[test,logging] --resolution=${{ matrix.version.resolution }} --system - # TODO: remove pin once reverse readline fixed - uv pip install monty==2024.7.12 --system + # TODO: test monty fix for reverse readline + pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending - name: Run Tests run: pytest --capture=no --cov --cov-report=xml From 48422c37f2faf6c578d64f59f73f302ee4e004d3 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 13:34:49 +0800 Subject: [PATCH 2/7] ensure pip env consistency --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9c95b1d8..755fdd43 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: uv pip install -e .[test,logging] --resolution=${{ matrix.version.resolution }} --system # TODO: test monty fix for reverse readline - pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending + uv pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending --system - name: Run Tests run: pytest --capture=no --cov --cov-report=xml From 77518b5bef22a3eb9eadab3a9f83fa453bb1d0fd Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 20:52:30 +0800 Subject: [PATCH 3/7] remove reverse readline --- chgnet/utils/vasp_utils.py | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/chgnet/utils/vasp_utils.py b/chgnet/utils/vasp_utils.py index 96943d3c..cbe909cd 100644 --- a/chgnet/utils/vasp_utils.py +++ b/chgnet/utils/vasp_utils.py @@ -5,7 +5,7 @@ import warnings from typing import TYPE_CHECKING -from monty.io import reverse_readfile +from monty.io import zopen from monty.os.path import zpath from pymatgen.io.vasp.outputs import Oszicar, Vasprun @@ -58,13 +58,11 @@ def parse_vasp_dir( exception_on_bad_xml=False, ) - charge, mag_x, mag_y, mag_z, header, all_lines = [], [], [], [], [], [] + charge, mag_x, mag_y, mag_z, header = [], [], [], [], [] - for line in reverse_readfile(outcar_path): - clean = line.strip() - all_lines.append(clean) + with zopen(outcar_path, encoding="utf-8") as file: + all_lines = [line.strip() for line in file] - all_lines.reverse() # For single atom systems, VASP doesn't print a total line, so # reverse parsing is very difficult # for SOC calculations only @@ -79,23 +77,21 @@ def parse_vasp_dir( if clean.startswith("# of ion"): header = re.split(r"\s{2,}", clean.strip()) header.pop(0) - else: - m = re.match(r"\s*(\d+)\s+(([\d\.\-]+)\s+)+", clean) - if m: - tokens = [float(token) for token in re.findall(r"[\d\.\-]+", clean)] - tokens.pop(0) - if read_charge: - charge.append(dict(zip(header, tokens))) - elif read_mag_x: - mag_x.append(dict(zip(header, tokens))) - elif read_mag_y: - mag_y.append(dict(zip(header, tokens))) - elif read_mag_z: - mag_z.append(dict(zip(header, tokens))) - elif clean.startswith("tot"): - if ion_step_count == (len(mag_x_all) + 1): - mag_x_all.append(mag_x) - read_charge = read_mag_x = read_mag_y = read_mag_z = False + elif re.match(r"\s*(\d+)\s+(([\d\.\-]+)\s+)+", clean): + tokens = [float(token) for token in re.findall(r"[\d\.\-]+", clean)] + tokens.pop(0) + if read_charge: + charge.append(dict(zip(header, tokens))) + elif read_mag_x: + mag_x.append(dict(zip(header, tokens))) + elif read_mag_y: + mag_y.append(dict(zip(header, tokens))) + elif read_mag_z: + mag_z.append(dict(zip(header, tokens))) + elif clean.startswith("tot"): + if ion_step_count == (len(mag_x_all) + 1): + mag_x_all.append(mag_x) + read_charge = read_mag_x = read_mag_y = read_mag_z = False if clean == "total charge": read_charge = True read_mag_x = read_mag_y = read_mag_z = False From 170c469718b131837829efccff3d3f311bee8cac Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 20:53:03 +0800 Subject: [PATCH 4/7] remove monty pin --- .github/workflows/test.yml | 3 --- pyproject.toml | 1 - 2 files changed, 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 755fdd43..95b4a9a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,9 +34,6 @@ jobs: pip install uv uv pip install -e .[test,logging] --resolution=${{ matrix.version.resolution }} --system - # TODO: test monty fix for reverse readline - uv pip install git+https://github.com/DanielYang59/monty.git@readline-line-ending --system - - name: Run Tests run: pytest --capture=no --cov --cov-report=xml env: diff --git a/pyproject.toml b/pyproject.toml index ce44d983..5252b40e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ license = { text = "Modified BSD" } dependencies = [ "ase>=3.23.0", "cython>=3", - # "monty==2024.7.12", # TODO: restore once readline fixed # "numpy>=1.26", # TODO: remove after test "numpy>=2.0.0", "nvidia-ml-py3>=7.352.0", From a594b61b783fd9ed7b176f2b333115fcab0ffed9 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 20:53:19 +0800 Subject: [PATCH 5/7] test NP1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5252b40e..8ad8c14c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ dependencies = [ "ase>=3.23.0", "cython>=3", # "numpy>=1.26", # TODO: remove after test - "numpy>=2.0.0", + "numpy==1.26", "nvidia-ml-py3>=7.352.0", "pymatgen>=2024.9.10", "torch>=2.4.1", From a02310d5f3772cebb4d46a0da5655f4ed6e42c0a Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 21:01:48 +0800 Subject: [PATCH 6/7] use readlines --- chgnet/utils/vasp_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chgnet/utils/vasp_utils.py b/chgnet/utils/vasp_utils.py index cbe909cd..82ee659c 100644 --- a/chgnet/utils/vasp_utils.py +++ b/chgnet/utils/vasp_utils.py @@ -61,7 +61,7 @@ def parse_vasp_dir( charge, mag_x, mag_y, mag_z, header = [], [], [], [], [] with zopen(outcar_path, encoding="utf-8") as file: - all_lines = [line.strip() for line in file] + all_lines = [line.strip() for line in file.readlines()] # For single atom systems, VASP doesn't print a total line, so # reverse parsing is very difficult From 3e875cb5da9c0a6b2dd79b9b4f78f1ffe501719e Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sun, 15 Sep 2024 21:03:18 +0800 Subject: [PATCH 7/7] revert numpy version pin to > 1.26 to support NP1 --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8ad8c14c..ae3a444c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,8 +9,7 @@ license = { text = "Modified BSD" } dependencies = [ "ase>=3.23.0", "cython>=3", - # "numpy>=1.26", # TODO: remove after test - "numpy==1.26", + "numpy>=1.26", "nvidia-ml-py3>=7.352.0", "pymatgen>=2024.9.10", "torch>=2.4.1",