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

Atomicrex interface broken with read_only #970

Closed
Leimeroth opened this issue Jan 29, 2024 · 6 comments · Fixed by #971
Closed

Atomicrex interface broken with read_only #970

Leimeroth opened this issue Jan 29, 2024 · 6 comments · Fixed by #971

Comments

@Leimeroth
Copy link
Member

Some changes on the HDF interface broke the atomicrex functionality, Old jobs can not be loaded and new ones can not be created.
Definition of potentials fails with an AttributeError because read_only is not defined.
Example:

AttributeError                            Traceback (most recent call last)
Cell In[27], line 13
     10 else:
     11     continue
---> 13 job.potential = pyih.atomicrexConstrainedMishinCuPotential(cutoff=cutoff, ele=ele, seed=i, r_short_max=0.95*min_d)
     14 job.input.parameter_constraints = constraints.copy()
     15 job.structures = s

File ~/git_projects/PythonScripts/pyiron_helper.py:671, in atomicrexConstrainedMishinCuPotential(cutoff, ele, p, seed, r_short_max)
    668 def atomicrexConstrainedMishinCuPotential(
    669     cutoff, ele, p=None, seed=42, r_short_max=2.35
    670 ):
--> 671     pot = atomicrexMishinCuPotential(
    672         cutoff=cutoff, ele=ele, p=p, seed=seed, r_short_max=r_short_max
    673     )
    674     V = pot.pair_interactions[f"V_{ele}{ele}"]
    675     rho = pot.electron_densities[f"rho_{ele}{ele}"]

File ~/git_projects/PythonScripts/pyiron_helper.py:557, in atomicrexMishinCuPotential(cutoff, ele, p, seed, r_short_max)
    553     p = rnd.uniform(1e-2, 1.0, 21)
    555 factories = Factories()
--> 557 V = factories.functions.MishinCuV(
    558     f"V_{ele}{ele}",
    559     E1=0.5 * p[0],
    560     E2=0.5 * p[1],
    561     alpha1=2 * p[2],
    562     alpha2=2 * p[3],
    563     r01=3 * p[4],
    564     r02=3 * p[5],
    565     delta=0.01,
    566     cutoff=cutoff,
    567     h=0.5,
    568     S1=100,
    569     S2=10,
    570     S3=2,
    571     rs1=1.6,
    572     rs2=1.9,
    573     rs3=2.3,
    574     species=[ele, ele],
    575 )
    576 rho = factories.functions.MishinCuRho(
    577     f"rho_{ele}{ele}",
    578     a=p[8],
   (...)
    583     species=[ele, ele],
    584 )
    585 rho.screening = factories.functions.x_pow_n_cutoff(
    586     identifier="rho_screen", cutoff=cutoff, h=0.5, N=4, species=[ele, ele]
    587 )

File ~/git_projects/pyiron_contrib/pyiron_contrib/atomistics/atomicrex/function_factory.py:206, in FunctionFactory.MishinCuV(identifier, E1, E2, alpha1, alpha2, r01, r02, delta, cutoff, h, S1, rs1, S2, rs2, S3, rs3, species)
    204 product_func = FunctionFactory.product(identifier, species)
    205 sum_func = FunctionFactory.sum(identifier="MorseSum", species=species)
--> 206 morse1 = FunctionFactory.morse_A(
    207     identifier="Morse1", D0=E1, r0=r01, alpha=alpha1, species=species
    208 )
    209 morse2 = FunctionFactory.morse_A(
    210     identifier="Morse2", D0=E2, r0=r02, alpha=alpha2, species=species
    211 )
    212 c = FunctionFactory.constant(
    213     identifier="delta", constant=delta, species=species
    214 )

File ~/git_projects/pyiron_contrib/pyiron_contrib/atomistics/atomicrex/function_factory.py:153, in FunctionFactory.morse_A(identifier, D0, r0, alpha, species)
    151 @staticmethod
    152 def morse_A(identifier, D0, r0, alpha, species=["*", "*"]):
--> 153     return MorseA(identifier, D0, r0, alpha, species=species)

File ~/git_projects/pyiron_contrib/pyiron_contrib/atomistics/atomicrex/function_factory.py:863, in MorseA.__init__(self, identifier, D0, r0, alpha, species)
    859 def __init__(
    860     self, identifier=None, D0=None, r0=None, alpha=None, species=["*", "*"]
    861 ):
    862     super().__init__(identifier, species=species, is_screening_function=False)
--> 863     self.parameters.add_parameter(
    864         "D0",
    865         start_val=D0,
    866         enabled=True,
    867     )
    868     self.parameters.add_parameter(
    869         "r0",
    870         start_val=r0,
    871         enabled=True,
    872     )
    873     self.parameters.add_parameter(
    874         "alpha",
    875         start_val=alpha,
    876         enabled=True,
    877     )

File ~/git_projects/pyiron_contrib/pyiron_contrib/atomistics/atomicrex/function_factory.py:1519, in FunctionParameterList.add_parameter(self, param, start_val, enabled, reset, min_val, max_val, tag, fitable)
   1492 def add_parameter(
   1493     self,
   1494     param,
   (...)
   1501     fitable=True,
   1502 ):
   1503     """
   1504     Add a function parameter named param to a function.
   1505     This needs to be done manually for user functions and
   (...)
   1517         fitable (bool, optional): [description]. Changing could cause bugs. Defaults to True.
   1518     """
-> 1519     self[param] = FunctionParameter(
   1520         param,
   1521         start_val,
   1522         enabled=enabled,
   1523         reset=reset,
   1524         min_val=min_val,
   1525         max_val=max_val,
   1526         tag=tag,
   1527         fitable=fitable,
   1528     )

File ~/git_projects/pyiron_contrib/pyiron_contrib/atomistics/atomicrex/function_factory.py:1395, in FunctionParameter.__init__(self, param, start_val, enabled, reset, min_val, max_val, fitable, tag)
   1384 def __init__(
   1385     self,
   1386     param=None,
   (...)
   1393     tag=None,
   1394 ):
-> 1395     self.param = param
   1396     self.start_val = start_val
   1397     self.enabled = enabled

File ~/git_projects/pyiron_base/pyiron_base/interfaces/lockable.py:76, in sentinel.<locals>.f(self, *args, **kwargs)
     74 if target in ("read_only", "_read_only"):
     75     return meth(self, *args, **kwargs)
---> 76 return dispatch_or_error(self, *args, **kwargs)

File ~/git_projects/pyiron_base/pyiron_base/interfaces/lockable.py:53, in sentinel.<locals>.dispatch_or_error(self, *args, **kwargs)
     51 if method not in ("error", "warning"):
     52     method = "error"
---> 53 if self.read_only and method == "error":
     54     raise Locked(
     55         "Object is currently locked!  Use unlocked() if you know what you are doing."
     56     )
     57 elif self.read_only and method == "warning":

File ~/git_projects/pyiron_base/pyiron_base/storage/datacontainer.py:388, in DataContainer.__getattr__(self, name)
    386     return self[name]
    387 except KeyError:
--> 388     raise AttributeError(name) from None

AttributeError: read_only

Do you have a recommended way fix this @pmrv ?

@Leimeroth
Copy link
Member Author

Calling super.init within the FunctionParameter class seems to fix it. I guess that is the simplest variant.

@pmrv
Copy link
Contributor

pmrv commented Jan 29, 2024

That sounds like it would be the issue, since you are deriving from DataContainer there anyway.

@pmrv
Copy link
Contributor

pmrv commented Jan 29, 2024

I also noticed that you define a lock method on FunctionParameter. That might conflict with a method of the same name on DataContainer (inherited from Lockable in pyiron_base).

@Leimeroth
Copy link
Member Author

I renamed it to lock_value.

@Leimeroth
Copy link
Member Author

The notebook tests fail, but I don"t really see how my PR influences them.

@pmrv
Copy link
Contributor

pmrv commented Jan 29, 2024

Seems related to #949.

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

Successfully merging a pull request may close this issue.

2 participants