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

Restore Python 3.8 compatibility for dictionary merge #63

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python/solid_dmft/dmft_tools/matheval.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ class MathExpr(object):
"max": max,
"pow": pow,
"round": round,
} | {key: value for (key, value) in vars(math).items() if not key.startswith("_")}
}
functions.update(
{key: value for (key, value) in vars(math).items() if not key.startswith("_")}
)

def __init__(self, expr):
if any(elem in expr for elem in "\n#"):
Expand All @@ -53,4 +56,4 @@ def __init__(self, expr):
self.code = compile(node, "<string>", "eval")

def __call__(self, **kwargs):
return eval(self.code, {"__builtins__": None}, self.functions | kwargs)
return eval(self.code, {"__builtins__": None}, {**self.functions, **kwargs})
8 changes: 4 additions & 4 deletions python/solid_dmft/dmft_tools/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def solve(self, **kwargs):

# Solve the impurity problem for icrsh shell
# *************************************
self.triqs_solver.solve(h_int=self.h_int, **(self.solver_params | random_seed ))
self.triqs_solver.solve(h_int=self.h_int, **{ **self.solver_params, **random_seed })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be an option to just store the keyword directly in line 352 in self.solver_params , i.e.:

self.solver_params['random_seed'] = int(self.random_seed_generator(it=kwargs["it"], rank=mpi.rank))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not overwrite solver_params['random_seed'] in-place, because that should be the value from read_config and if you overwrite this the wrong value might be serialized to the output file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the original solver_params that are stored in the h5 are owned by dmft_cylce, and stored from there to the h5, the dict withing the solid_dmft solver object is not used for storage. Or do you mean other output? I think that should be save to overwrite then no? At least I do not see a problem right now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dictionaries (and lists) are reference types. They are not copied (unless explicitly using .copy()):

>>> a = { "foo": 1 }
>>> b = a
>>> b["foo"] = 2
>>> a
{'foo': 2}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes of course. Somehow I wasn't sure with a dict but you are of course right. Then we do not want to change it ;-)

# *************************************

# call postprocessing
Expand All @@ -413,7 +413,7 @@ def solve(self, **kwargs):

# Solve the impurity problem for icrsh shell
# *************************************
self.triqs_solver.solve(h_int=self.h_int, **(self.solver_params | random_seed ))
self.triqs_solver.solve(h_int=self.h_int, **{ **self.solver_params, **random_seed })
# *************************************

# call postprocessing
Expand Down Expand Up @@ -587,7 +587,7 @@ def make_positive_definite(G):

# Solve the impurity problem for icrsh shell
# *************************************
self.triqs_solver.solve(h_int=self.h_int, **(self.solver_params | random_seed ))
self.triqs_solver.solve(h_int=self.h_int, **{ **self.solver_params, **random_seed })
# *************************************

# call postprocessing
Expand All @@ -604,7 +604,7 @@ def make_positive_definite(G):

# Solve the impurity problem for icrsh shell
# *************************************
self.triqs_solver.solve(h_int=self.h_int, **(self.solver_params | random_seed ))
self.triqs_solver.solve(h_int=self.h_int, **{ **self.solver_params, **random_seed })
# *************************************

# call postprocessing
Expand Down
Loading