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

Added functionality and some fixes #1

Merged
merged 14 commits into from
Nov 6, 2022
Merged

Conversation

hejamu
Copy link
Contributor

@hejamu hejamu commented Apr 5, 2021

Hi all,

I use this modified version of flamel in my research. Maybe this is interesting for others.

@hejamu
Copy link
Contributor Author

hejamu commented Apr 5, 2021

I'll take the liberty of tagging @orbeckst and @dotsdl, since the original developer is no longer active in this field?

@orbeckst
Copy link
Member

orbeckst commented Apr 5, 2021

Sure, thanks for the contribution, @hejamu !

Please ping me when you need a review.

Generally speaking, smaller/focused PRs are easier to handle than big ones.

@hejamu
Copy link
Contributor Author

hejamu commented Apr 5, 2021

Thanks @orbeckst.

Yeah, it's a bit of a mess with my commits... I didn't think about contributing my changes back when I started it... I guess I will just open the PR to initiate the discussion about it. The majority of the changes are just small additions and documentation.

@hejamu hejamu marked this pull request as ready for review April 5, 2021 17:42
Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

@hejamu I had a few minutes to look over your PR. I am not an expert on flamel but apparently I am the only person looking at things at the moment so here we go.

The docs changes all look very good.

New output plugins are also good. I am happy to see that the plugin system works.

My primary concern is with code duplication, including how constants are sprinkled throughout the code. It would help a lot if you could come up with a way to collect all unit-conversion related code (including constants) in a separate module that is just imported in the other modules.

Similarly, at first glance there seems duplicated code in the plugins. If that's not the case then let me know. Otherwise this should all go into a plugin base class or you derive your class from another class that already has these (but it's cleaner to have a common base class so that changes in one class do not affect the other).

output/pickle.py Outdated

class Pickle:
name = 'pickle'
k_b = 8.3144621E-3
Copy link
Member

Choose a reason for hiding this comment

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

If we need constants then we should have them all in one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be possible to use scipy.constants since scipy is a dependency of alchemlyb anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, good idea.

Copy link
Member

Choose a reason for hiding this comment

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

(You'll still have to add it to flamel's setup.py to be explicit.)

Copy link
Member

Choose a reason for hiding this comment

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

Er, sorry... there's no setup.py. In fact there's no installation at all... see #3

output/simple.py Outdated
Comment on lines 23 to 32
if args.unit == 'kT':
conversion = 1.0
args.unit = 'kT'
elif args.unit == 'kJ' or args.unit == 'kJ/mol':
conversion = t * self.k_b
args.unit = 'kJ/mol'
elif args.unit == 'kcal' or args.unit == 'kcal/mol':
conversion = 0.239006 * t * self.k_b
args.unit = 'kcal/mol'

Copy link
Member

Choose a reason for hiding this comment

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

duplication of conversion code

Comment on lines 132 to 142

if args.unit == 'kT':
conversion = 1.0
args.unit = 'kT'
elif args.unit == 'kJ' or args.unit == 'kJ/mol':
conversion = 1.0 * t * self.k_b
args.unit = 'kJ/mol'
elif args.unit == 'kcal' or args.unit == 'kcal/mol':
conversion = 0.239006 * t * self.k_b
args.unit = 'kcal/mol'

Copy link
Member

Choose a reason for hiding this comment

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

duplication of conversion code — can this be put into a separate, reusable function ?

(There's some discussion on units in alchemlyb alchemistry/alchemlyb#125 but it will be a while until that is ready so in the meantime, flanel should certainly provide a way for unit conversion.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Putting this code and its duplicates in a separate function is definitely the best way. The linked discussion is very interesting though.

Copy link
Member

Choose a reason for hiding this comment

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

By all means, contribute to the discussion! Contributors are very welcome.

output/text.py Outdated

class Text:
name = 'text'
k_b = 8.3144621E-3
Copy link
Member

Choose a reason for hiding this comment

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

keep constants in one place

output/text.py Outdated
Comment on lines 38 to 55
def ls(cls, estimators):
"""
Return a list of lambda values
:param estimators: Series
List of estimator plugins
:return:
The list of lambda values
"""
ls = []
if estimators:
if estimators[0].needs_dhdls:
means = estimators[0].dhdls.mean(level=estimators[0].dhdls.index.names[1:])
ls = np.array(means.reset_index()[means.index.names[:]])
elif estimators[0].needs_u_nks:
means = estimators[0].u_nks.mean(level=estimators[0].u_nks.index.names[1:])
ls = np.array(means.reset_index()[means.index.names[:]])

return ls
Copy link
Member

Choose a reason for hiding this comment

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

same code as in Pickle plugin?

output/text.py Outdated
return l_types

@classmethod
def segments(cls, estimators):
Copy link
Member

Choose a reason for hiding this comment

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

duplicate code?

output/text.py Outdated
Comment on lines 134 to 142
if args.unit == 'kT':
conversion = 1.0
args.unit = 'kT'
elif args.unit == 'kJ' or args.unit == 'kJ/mol':
conversion = t * self.k_b
args.unit = 'kJ/mol'
elif args.unit == 'kcal' or args.unit == 'kcal/mol':
conversion = 0.239006 * t * self.k_b
args.unit = 'kcal/mol'
Copy link
Member

Choose a reason for hiding this comment

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

duplicated code... with lots of hard-coded constants :-p

ind = np.array(ind, dtype=int)
dhdl_sum = dhdl_.dot(ind)
uncorrelated_dfs.append(alchemlyb.preprocessing.statistical_inefficiency(df, dhdl_sum, lower, conservative=False))
uncorrelated_dfs.append(alchemlyb.preprocessing.statistical_inefficiency(df, lower=lower))
Copy link
Member

Choose a reason for hiding this comment

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

Set explicitly conservative=True.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See below.

Comment on lines 54 to 56
ind = np.array(l, dtype=bool)
ind = np.array(ind, dtype=int)
dhdl_sum = dhdl_.dot(ind)
Copy link
Member

Choose a reason for hiding this comment

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

What's the rationale for not using dhdl_sum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't recall why this change was made.... I will have to look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a temporary change due to alchemistry/alchemlyb#166. We identified the cause just now. I reverted the change.

@hejamu
Copy link
Contributor Author

hejamu commented May 4, 2021

@orbeckst Thanks for looking into this so thoroughly. The units really are a mess... I hope to get to the changes soon :)

@orbeckst
Copy link
Member

@hejamu are you still interested in finalizing the PR?

About constants: use scipy.constants (alchemlyb switched to using it, too).

Main changes:
- make the `energy_unit` attribute propagate through the `uncorrelate` plugins.
- use alchemlybs new conversion feature to facilitate easy unit conversion.
- Removed `text` output plugin. This was just a file version of the `alchemical-analysis` output. Moved into the `alchemical-analysis` plugin
@hejamu
Copy link
Contributor Author

hejamu commented Sep 21, 2021

Sorry, this was low priority for me in the last months. I think these change are a step in the right direction.

@orbeckst
Copy link
Member

Overall I like the code clean-up and how much @xiki-tempula 's new units system improved the code here!

In the absence of any tests (see #9 ) I am going to just say "ok". My feeling is that adding CI with tests (#9) is the next important milestone to give flamel a chance to grow and gain a user base.

@orbeckst
Copy link
Member

@xiki-tempula @harlor do you want to have a look at this PR before a merge?

@orbeckst orbeckst added the enhancement New feature or request label Sep 22, 2021
@orbeckst orbeckst self-assigned this Sep 23, 2021
@orbeckst
Copy link
Member

orbeckst commented Nov 6, 2022

I manually merged this branch into master in 91d1cc4 so the code is in the retroactive 0.2.0.

I'll also merge into develop so that the branch shows up merged but we are not using develop anymore.

@orbeckst orbeckst merged commit 853ae2c into alchemistry:develop Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants