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

Time convergence #168

Merged
merged 21 commits into from
Oct 22, 2021
Merged

Time convergence #168

merged 21 commits into from
Oct 22, 2021

Conversation

xiki-tempula
Copy link
Collaborator

As discussed in #159, the time convergence analysis could be implemented as a function.

@xiki-tempula xiki-tempula marked this pull request as draft September 26, 2021 11:13
@codecov
Copy link

codecov bot commented Sep 26, 2021

Codecov Report

Merging #168 (f42dcde) into master (5f81d70) will increase coverage by 0.10%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #168      +/-   ##
==========================================
+ Coverage   97.85%   97.96%   +0.10%     
==========================================
  Files          20       22       +2     
  Lines        1214     1279      +65     
  Branches      258      271      +13     
==========================================
+ Hits         1188     1253      +65     
  Misses          5        5              
  Partials       21       21              
Impacted Files Coverage Δ
src/alchemlyb/convergence/__init__.py 100.00% <100.00%> (ø)
src/alchemlyb/convergence/convergence.py 100.00% <100.00%> (ø)
src/alchemlyb/visualisation/convergence.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5f81d70...f42dcde. Read the comment docs.

@xiki-tempula xiki-tempula marked this pull request as ready for review September 26, 2021 12:43
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.

Good to have these first convergence functions. However, they should be in their own module alchemlyb.convergence as they are not postprocessing, see https://alchemlyb.readthedocs.io/en/latest/api_principles.html.

Please

  1. create new top level convergence module
  2. include in docs
  3. update API principles with short description of new module
  4. update CHANGES

I'd also think the convergence results dataframe could be improved (see comments).

Finally, if you change the argument processing of the plot_convergence function then you don't have to effectively change its API.

Please see inline for any other comments.

src/alchemlyb/postprocessors/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/postprocessors/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/postprocessors/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/postprocessors/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/postprocessors/convergence.py Outdated Show resolved Hide resolved
forward_list = []
forward_error_list = []
for i in range(1, num + 1):
logger.info('Forward analysis: {:.2f}%'.format(i / num))
Copy link
Member

Choose a reason for hiding this comment

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

fraction of data i/num should be in final dataframe

Copy link
Member

Choose a reason for hiding this comment

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

thanks for adding, please see new comments about making it a float

src/alchemlyb/visualisation/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/visualisation/convergence.py Show resolved Hide resolved
src/alchemlyb/visualisation/convergence.py Outdated Show resolved Hide resolved
src/alchemlyb/visualisation/convergence.py Show resolved Hide resolved

.. versionadded:: 0.6.0
'''
logger = logging.getLogger('alchemlyb.postprocessors.'
Copy link
Member

Choose a reason for hiding this comment

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

convergence

A list of error from the last X% of data.
data : Dataframe or 4 Lists
Output Dataframe from
:func:`~alchemlyb.postprocessors.convergence.forward_backward_convergence`.
Copy link
Member

Choose a reason for hiding this comment

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

convergence

A list of free energy estimate from the last X% of data.
backward_error : List
A list of error from the last X% of data.
data : Dataframe or 4 Lists
Copy link
Member

Choose a reason for hiding this comment

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

are these really lists, maybe better array_like

@@ -32,12 +31,28 @@ def plot_convergence(forward, forward_error, backward, backward_error,
The code is taken and modified from
`Alchemical Analysis <https://github.com/MobleyLab/alchemical-analysis>`_.

The units variable is for labelling only. Changing it doesn't change the
unit of the underlying variable.
If `dataframe` is not provide, the units variable is for labelling only.
Copy link
Member

Choose a reason for hiding this comment

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

If `data` is not an :class:pandas.Dataframe` produced by :func:`.....forward_backward_convergence`  ...

if len(data) == 1 and isinstance(data[0], pd.DataFrame):
dataframe = get_unit_converter(units)(data)
forward = dataframe['Forward'].to_numpy()
forward_error = dataframe['F. Error'].to_numpy()
Copy link
Member

Choose a reason for hiding this comment

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

How could "F. Error" pass the tests, given that you changed the column names?

forward_list = []
forward_error_list = []
for i in range(1, num + 1):
logger.info('Forward analysis: {:.2f}%'.format(i / num))
Copy link
Member

Choose a reason for hiding this comment

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

Multiply by 100 for %.

backward_list = []
backward_error_list = []
for i in range(1, num + 1):
logger.info('Backward analysis: {:.2f}%'.format(i / num))
Copy link
Member

Choose a reason for hiding this comment

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

x 100 for %

'Forward_Error': forward_error_list,
'Backward': backward_list,
'Backward_Error': backward_error_list},
index=['{}/{}'.format(i, num) for i in range(1, num + 1)])
Copy link
Member

@orbeckst orbeckst Oct 5, 2021

Choose a reason for hiding this comment

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

I prefer a numerical column instead of a string. If you want to keep it as the index, also add a column data_fraction where you just store the float i/num. The numerical value is more valuable, I think, because you can directly plot against it. (Or replace the string with the float and keep it the rest as is.)

Copy link
Member

Choose a reason for hiding this comment

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

I realize my original comment might have been misleading where I talked about i/num, hope the above makes my thinking clearer.

@orbeckst
Copy link
Member

orbeckst commented Oct 5, 2021

Thanks for addressing my comments. I have a bunch of additional comments added (and still needs CHANGES entry). Thanks!

@orbeckst
Copy link
Member

orbeckst commented Oct 5, 2021

Tests fail with something that looks like passing through a list or array when a dataframe is expected.

@xiki-tempula
Copy link
Collaborator Author

@orbeckst Thank you for the review. Sorry I was busy in the last few days.

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.

Please see change suggestions (you should be able to just apply them) and the remaining docs issue. Thanks!

If `dataframe` is not provide, the units variable is for labelling only.
If `data` is not an :class:pandas.Dataframe` produced by
:func:`~alchemlyb.convergence.forward_backward_convergence`,
the unit will be adjusted accoridng to the units
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
the unit will be adjusted accoridng to the units
the unit will be adjusted according to the units

src/alchemlyb/tests/test_convergence.py Outdated Show resolved Hide resolved
CHANGES Outdated Show resolved Hide resolved
src/alchemlyb/visualisation/convergence.py Show resolved Hide resolved
xiki-tempula and others added 3 commits October 10, 2021 09:03
@xiki-tempula xiki-tempula requested a review from orbeckst October 10, 2021 08:26
@xiki-tempula
Copy link
Collaborator Author

@orbeckst Sorry, I wonder if you would mind giving a final review and I will get it merged then.

@orbeckst orbeckst self-assigned this Oct 22, 2021
@xiki-tempula xiki-tempula merged commit 592f38b into alchemistry:master Oct 22, 2021
@xiki-tempula xiki-tempula deleted the convergence branch October 22, 2021 15:55
@orbeckst
Copy link
Member

@xiki-tempula I was working on the commit message, which is now lost because you just merged — that's why I had assigned myself to indicate that I would be merging it. Let's agree that before merging we claim the Assignee to avoid confusion.

@xiki-tempula
Copy link
Collaborator Author

xiki-tempula commented Oct 22, 2021

@orbeckst I'm very sorry. I saw that it has been approved so I just went ahead and merged it. If I saw it has been assigned in the future, I will not touch it.

@orbeckst orbeckst mentioned this pull request Oct 29, 2021
5 tasks
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 this pull request may close these issues.

2 participants