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

Optimization: change in spectrum should not be calculated during pre-simulation #90

Open
jussiks opened this issue Oct 26, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@jussiks
Copy link
Member

jussiks commented Oct 26, 2020

When user chooses to run a simulation before optimization, optimization will not start until the change in simulated energy spectrum is below a user-defined threshold. The change is calculated at regular intervals.

This check should not be done when the simulation is still in pre-simulation. As data from pre-simulation is discarded, simulated spectrum will simply not change at all before actual simulation kicks in. This causes the optimization to start before it should.

This bug affects elements that have already been simulated (i.e. number of observed atoms > 0). It does not affect elements with no previous simulation data, as in this case the check returns infinity instead of zero.

Previous versions of Potku (pre-Jan 2020 at least) implemented this check correctly.

How to reproduce

  • Run a simulation for some element to gather initial data.
  • Set the number of pre-simulation ions to a reasonably large value to ensure that pre-simulation runs for a long enough time.
  • Choose the simulated element in the Optimization menu.
  • Untick "Skip simulation" checkbox.
  • Set "Min. run time" (= time of the first check) and "Seconds between checks" to small values. The first two spectrum checks need to happen during pre-simulation to trigger this bug.

Example settings shown below:
optim_menu

How to fix

The observable stream returned by ElementSimulation.run consists of dictionaries that contain the pre-simulation status. This status should be used as a condition for running the spectra check. For this to be possible, merging of spectrum check and the observable needs to be reworked.

This bug is also mentioned in a FIXME in the source code:

potku/modules/nsgaii.py

Lines 230 to 253 in 5b8ebd2

# FIXME spectra_chk should only be performed when pre-simulation
# has finished, otherwise there will be no new observed atoms
# and the difference between the two spectra is 0
spectra_chk = rx.timer(self.check_min, self.check_time).pipe(
ops.merge(ct_check),
ops.map(lambda _: get_optim_espe(
self.element_simulation, self.optimization_type)),
ops.scan(
lambda prev_espe, next_espe: (prev_espe[1], next_espe),
seed=[None, None]),
ops.map(lambda espes: calculate_change(
*espes, self.element_simulation.channel_width)),
ops.take_while(
lambda change: change > self.stop_percent and not
ct.is_cancellation_requested()
),
ops.do_action(
on_completed=ct.request_cancellation)
)
merged = rx.merge(observable, spectra_chk).pipe(
ops.take_while(
lambda x: not isinstance(x, dict) or x[MCERD.IS_RUNNING],
inclusive=True)
)

Additionally, user should be better informed about the progress made during optimization. A constant barrage of get_espe output is not very informative. The output should be suppressed and replaced with results from spectrum check etc.

@jussiks jussiks added the bug Something isn't working label Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant