Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests.pt.test_training.TestEnergyZBLModelSeA.test_dp_train failed #3744

Closed
njzjz opened this issue May 6, 2024 · 1 comment · Fixed by #3757
Closed

tests.pt.test_training.TestEnergyZBLModelSeA.test_dp_train failed #3744

njzjz opened this issue May 6, 2024 · 1 comment · Fixed by #3757
Assignees
Labels

Comments

@njzjz
Copy link
Member

njzjz commented May 6, 2024

――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestEnergyZBLModelSeA.test_dp_train ――――――――――――――――――――――――――――――――――――――――――――――――――――――――

self = <tests.pt.test_training.TestEnergyZBLModelSeA testMethod=test_dp_train>

    def test_dp_train(self):
        # test training from scratch
>       trainer = get_trainer(deepcopy(self.config))

pt/test_training.py:32:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../deepmd/pt/entrypoints/main.py:189: in get_trainer
    trainer = training.Trainer(
../../deepmd/pt/train/training.py:335: in __init__
    self.model = get_single_model(
../../deepmd/pt/train/training.py:268: in get_single_model
    model = get_zbl_model(deepcopy(_model_params)).to(DEVICE)
../../deepmd/pt/model/model/__init__.py:127: in get_zbl_model
    pt_model = PairTabAtomicModel(
../../deepmd/utils/plugin.py:88: in __call__
    obj.__init__(*args, **kwargs)
../../deepmd/pt/model/atomic_model/pairtab_atomic_model.py:80: in __init__
    self.tab = self._set_pairtab(tab_file, rcut)
../../deepmd/pt/model/atomic_model/pairtab_atomic_model.py:120: in _set_pairtab
    return PairTab(tab_file, rcut)
../../deepmd/utils/pair_tab.py:38: in __init__
    self.reinit(filename, rcut)
../../deepmd/utils/pair_tab.py:56: in reinit
    self.vdata = np.loadtxt(filename)
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/npyio.py:1373: in loadtxt
    arr = _read(fname, dtype=dtype, comment=comment, delimiter=delimiter,
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/npyio.py:992: in _read
    fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/_datasource.py:193: in open
    return ds.open(path, mode, encoding=encoding, newline=newline)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <numpy.DataSource object at 0x151576314400>, path = 'source/tests/pt/model/water/data/zbl_tab_potential/H2O_tab_potential.txt', mode = 'rt'
encoding = None, newline = None

    def open(self, path, mode='r', encoding=None, newline=None):
        """
        Open and return file-like object.

        If `path` is an URL, it will be downloaded, stored in the
        `DataSource` directory and opened from there.

        Parameters
        ----------
        path : str
            Local file path or URL to open.
        mode : {'r', 'w', 'a'}, optional
            Mode to open `path`.  Mode 'r' for reading, 'w' for writing,
            'a' to append. Available modes depend on the type of object
            specified by `path`. Default is 'r'.
        encoding : {None, str}, optional
            Open text file with given encoding. The default encoding will be
            what `io.open` uses.
        newline : {None, str}, optional
            Newline to use when reading text file.

        Returns
        -------
        out : file object
            File object.

        """

        # TODO: There is no support for opening a file for writing which
        #       doesn't exist yet (creating a file).  Should there be?

        # TODO: Add a ``subdir`` parameter for specifying the subdirectory
        #       used to store URLs in self._destpath.

        if self._isurl(path) and self._iswritemode(mode):
            raise ValueError("URLs are not writeable")

        # NOTE: _findfile will fail on a new file opened for writing.
        found = self._findfile(path)
        if found:
            _fname, ext = self._splitzipext(found)
            if ext == 'bz2':
                mode.replace("+", "")
            return _file_openers[ext](found, mode=mode,
                                      encoding=encoding, newline=newline)
        else:
>           raise FileNotFoundError(f"{path} not found.")
E           FileNotFoundError: source/tests/pt/model/water/data/zbl_tab_potential/H2O_tab_potential.txt not found.

/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/_datasource.py:533: FileNotFoundError

 source/tests/pt/test_training.py85% ████████▋

――――――――――――――――――――――――――――――――――――――――――――――――――――――― TestEnergyZBLModelSeA.test_trainable ―――――――――――――――――――――――――――――――――――――――――――――――――――――――

self = <tests.pt.test_training.TestEnergyZBLModelSeA testMethod=test_trainable>

    def test_trainable(self):
        fix_params = deepcopy(self.config)
        fix_params["model"]["descriptor"]["trainable"] = False
        fix_params["model"]["fitting_net"]["trainable"] = False
        free_descriptor = hasattr(self, "not_all_grad") and self.not_all_grad
        if free_descriptor:
            # can not set requires_grad false for all parameters,
            # because the input coord has no grad, thus the loss if all set to false
            # we only check trainable for fitting net
            fix_params["model"]["descriptor"]["trainable"] = True
            trainer_fix = get_trainer(fix_params)
            model_dict_before_training = deepcopy(
                trainer_fix.model.get_fitting_net().state_dict()
            )
            trainer_fix.run()
            model_dict_after_training = deepcopy(
                trainer_fix.model.get_fitting_net().state_dict()
            )
        else:
>           trainer_fix = get_trainer(fix_params)

pt/test_training.py:63:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../deepmd/pt/entrypoints/main.py:189: in get_trainer
    trainer = training.Trainer(
../../deepmd/pt/train/training.py:335: in __init__
    self.model = get_single_model(
../../deepmd/pt/train/training.py:268: in get_single_model
    model = get_zbl_model(deepcopy(_model_params)).to(DEVICE)
../../deepmd/pt/model/model/__init__.py:127: in get_zbl_model
    pt_model = PairTabAtomicModel(
../../deepmd/utils/plugin.py:88: in __call__
    obj.__init__(*args, **kwargs)
../../deepmd/pt/model/atomic_model/pairtab_atomic_model.py:80: in __init__
    self.tab = self._set_pairtab(tab_file, rcut)
../../deepmd/pt/model/atomic_model/pairtab_atomic_model.py:120: in _set_pairtab
    return PairTab(tab_file, rcut)
../../deepmd/utils/pair_tab.py:38: in __init__
    self.reinit(filename, rcut)
../../deepmd/utils/pair_tab.py:56: in reinit
    self.vdata = np.loadtxt(filename)
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/npyio.py:1373: in loadtxt
    arr = _read(fname, dtype=dtype, comment=comment, delimiter=delimiter,
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/npyio.py:992: in _read
    fh = np.lib._datasource.open(fname, 'rt', encoding=encoding)
/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/_datasource.py:193: in open
    return ds.open(path, mode, encoding=encoding, newline=newline)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <numpy.DataSource object at 0x15156cb15870>, path = 'source/tests/pt/model/water/data/zbl_tab_potential/H2O_tab_potential.txt', mode = 'rt'
encoding = None, newline = None

    def open(self, path, mode='r', encoding=None, newline=None):
        """
        Open and return file-like object.

        If `path` is an URL, it will be downloaded, stored in the
        `DataSource` directory and opened from there.

        Parameters
        ----------
        path : str
            Local file path or URL to open.
        mode : {'r', 'w', 'a'}, optional
            Mode to open `path`.  Mode 'r' for reading, 'w' for writing,
            'a' to append. Available modes depend on the type of object
            specified by `path`. Default is 'r'.
        encoding : {None, str}, optional
            Open text file with given encoding. The default encoding will be
            what `io.open` uses.
        newline : {None, str}, optional
            Newline to use when reading text file.

        Returns
        -------
        out : file object
            File object.

        """

        # TODO: There is no support for opening a file for writing which
        #       doesn't exist yet (creating a file).  Should there be?

        # TODO: Add a ``subdir`` parameter for specifying the subdirectory
        #       used to store URLs in self._destpath.

        if self._isurl(path) and self._iswritemode(mode):
            raise ValueError("URLs are not writeable")

        # NOTE: _findfile will fail on a new file opened for writing.
        found = self._findfile(path)
        if found:
            _fname, ext = self._splitzipext(found)
            if ext == 'bz2':
                mode.replace("+", "")
            return _file_openers[ext](found, mode=mode,
                                      encoding=encoding, newline=newline)
        else:
>           raise FileNotFoundError(f"{path} not found.")
E           FileNotFoundError: source/tests/pt/model/water/data/zbl_tab_potential/H2O_tab_potential.txt not found.

/home/jz748/anaconda3/lib/python3.10/site-packages/numpy/lib/_datasource.py:533: FileNotFoundError
@njzjz njzjz added the bug label May 6, 2024
@njzjz
Copy link
Member Author

njzjz commented May 6, 2024

It happens when pytest is running in a different directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants