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

LennardJones raises Error when initialized without specified ndim #24

Closed
mpvanderschelling opened this issue Feb 8, 2024 · 1 comment

Comments

@mpvanderschelling
Copy link

The problem

  • The LennardJones Function has a dim_default of 2, but an ValueError is raised when the dimensionality that is given upon construction is nog in `range(6, 61)
  • This check is specified right after construction, before setting the default dimensionality. Therefore providing no argument (ndim=None) will raise the ValueError. This is inconsistant with the interface of the other named functions.

self.dim_default = 2

Minimal reproducible example

from opfunu.name_based.l_func import LennardJones
f = LennardJones(ndim=None)

will raise:

ValueError                                Traceback (most recent call last)
Cell In[13], [line 3](vscode-notebook-cell:?execution_count=13&line=3)
      [1](vscode-notebook-cell:?execution_count=13&line=1) from opfunu.name_based.l_func import LennardJones
----> [3](vscode-notebook-cell:?execution_count=13&line=3) f = LennardJones(ndim=None)

File [~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110), in LennardJones.__init__(self, ndim, bounds)
    [108](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:108) def __init__(self, ndim=None, bounds=None):
    [109](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:109)     if ndim not in range(6, 61):
--> [110](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:110)         raise ValueError("LennardJones dimensions must be in (6, 60)")
    [111](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:111)     super().__init__()
    [112](https://file+.vscode-resource.vscode-cdn.net/home/martin/Documents/GitHub/opfunu/notebooks/~/Documents/GitHub/opfunu/opfunu/name_based/l_func.py:112)     self.dim_changeable = True

ValueError: LennardJones dimensions must be in (6, 60)
@thieu1995
Copy link
Owner

@mpvanderschelling,

Thank you. I have fixed this problem.

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

No branches or pull requests

2 participants