-
Notifications
You must be signed in to change notification settings - Fork 188
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
Return correct shapes from Correlator #3848
Conversation
Check out this pull request on Review Jupyter notebook visual diffs & provide feedback on notebooks. Powered by ReviewNB |
3760cda
to
a1c5795
Compare
Use the shape(s) of the correlated observable(s) to deduce the shape of the correlation output. Extract time lags and sample size from the correlation matrix and provide methods `correlation_lags()` and `correlation_sizes()` instead.
Used to throw cryptic runtime_errors when one of the test used an observable tracking two particles (e.g. `No data can be added after finalize() was called.` or `Particle node for id 1 not found!`).
@KaiSzuttor while working on this PR, I realized the output of the import espressomd
from espressomd.accumulators import Correlator
from espressomd.observables import ParticlePositions
import numpy as np
system = espressomd.System(box_l=[1.0, 1.0, 1.0])
system.time_step = 0.05
system.cell_system.skin = 0.4
system.part.add(pos=[(0, 0, 0), (0.5, .5, 0)])
system.thermostat.set_langevin(kT=1.37, gamma=2.4, seed=42)
pos_obs = ParticlePositions(ids=(0,1))
c_pos1 = Correlator(obs1=pos_obs, tau_lin=16, tau_max=20., delta_N=10,
corr_operation="square_distance_componentwise",
compress1="discard1")
c_pos2 = Correlator(obs1=pos_obs, tau_lin=16, tau_max=20., delta_N=10,
corr_operation="scalar_product", compress1="discard1")
system.auto_update_accumulators.add(c_pos1)
system.auto_update_accumulators.add(c_pos2)
system.integrator.run(10000)
c_pos1.finalize()
c_pos2.finalize()
print(c_pos1.result().shape) # output: (33, 2, 3)
print(c_pos2.result().shape) # output: (33, 1) For the |
so you mean the shape is a function not only of the observable type but also of the operation? Isn't that expected? |
sure, but the espresso/src/core/accumulators/Correlator.cpp Lines 234 to 235 in f22be4c
this is surprising given that we already have the code logic to take the observable shape into account |
So, the correlator has a bug which needs a fix before we can go on with returning the correct shape, right? |
I just tried to implement a This gives us 2 options: throw an error when doing a scalar product of matrices (that's currently implemented in acfa0b4) which is an API breaking change, or not throw an error and trust the user can figure out why the correlation shape is 1. Same thing for tensor product. |
so our correlation function behaves like numpy correlate and assumes 1d data... I think there is no generic solution to correlating multidimensional data because the algorithms are not implemented in a generic fashion. |
What should we do then? Right now I throw an error if the user accidentally passes a matrix instead of a vector to the scalar product, because it was not originally designed to handle this case. There was no mechanism to prevent it because it didn't really make sense back then to calculate the scalar product of a I cannot think of an application where one would want to do a scalar product on flattened matrices, but maybe there is one, in which case this would no longer be possible because we do not offer the possibility to reshape an observable before passing it to the correlator. We already have an
|
i'm not so sure if this is a cat 1 issue to be resolved next... let's wait for @RudolfWeeber |
Agreed, refactoring the |
@@ -138,7 +139,9 @@ | |||
" for i in range(LOOPS):\n", | |||
" system.integrator.run(STEPS)\n", | |||
" correlator.finalize()\n", | |||
" msd_results.append(correlator.result())\n", | |||
" msd_results.append(np.column_stack((correlator.lag_times(),\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -385,7 +385,10 @@ | |||
"# Finalize the correlator and write to disk\n", | |||
"system.auto_update_accumulators.remove(msd)\n", | |||
"msd.finalize()\n", | |||
"numpy.savetxt(\"output.dat\", msd.result())\n", | |||
"numpy.savetxt(\"output.dat\",\n", | |||
" numpy.column_stack((msd.lag_times(),\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #3577
Description of changes:
Correlator
output arrays based on the dimensions of the input observablesCorrelator
observable