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

Particle type map goes out of sync when clearing particles #4645

Closed
jngrad opened this issue Jan 9, 2023 · 0 comments · Fixed by #4648
Closed

Particle type map goes out of sync when clearing particles #4645

jngrad opened this issue Jan 9, 2023 · 0 comments · Fixed by #4648
Assignees

Comments

@jngrad
Copy link
Member

jngrad commented Jan 9, 2023

The particle type map is updated when removing individual particles, but not when clearing all particles. The type map remains desynchronized until new particles are created. Affects all ESPResSo versions since 4.0.

MWE for 4.3-dev (tested on 30c7c23):

import espressomd
import espressomd.reaction_methods
import numpy as np
np.random.seed(seed=42)
system = espressomd.System(box_l=3 * [10.])
system.time_step = 0.02
system.cell_system.skin = 0.4
# set particles
type_A = 0
type_B = 1
system.part.add(pos=np.random.random((10, 3)) * system.box_l, type=10 * [type_B])
# set reaction 1A <-> 1B
RE = espressomd.reaction_methods.ReactionEnsemble(kT=1., exclusion_range=0., seed=42)
RE.add_reaction(reactant_types=[type_A], reactant_coefficients=[1],
                product_types=[type_B], product_coefficients=[1],
                gamma=0.001, default_charges={type_A: 0, type_B: 0})
RE.set_non_interacting_type(type=2)
# clear particle list
system.part.clear()
# state tracking is now out of sync
print(f"n_A = {system.number_of_particles(type=type_A)}")
print(f"n_B = {system.number_of_particles(type=type_B)}")
# triggering a cell system reset has no effect on state tracking
system.cell_system.set_n_square()
system.cell_system.set_regular_decomposition()
# reaction fails
RE.reaction(reaction_steps=4)

Output:

n_A = 0
n_B = 10
Traceback (most recent call last):
  File "/work/jgrad/espresso/build/mwe.py", line 27, in <module>
    RE.reaction(reaction_steps=4)
  File "script_interface.pyx", line 425, in espressomd.script_interface.ScriptInterfaceHelper.generate_caller.template_method
  File "script_interface.pyx", line 159, in espressomd.script_interface.PScriptInterface.call_method
RuntimeError: Particle node for id 0 not found!

Expected output:

n_A = 0
n_B = 0
@jngrad jngrad added this to the Espresso 4.2.1 milestone Jan 9, 2023
@jngrad jngrad self-assigned this Jan 9, 2023
jngrad added a commit that referenced this issue Jan 12, 2023
Fixes #4644
Fixes #4645
Pre-requisite to #4629

Description of changes:
- bugfix: the type map is now properly updated when clearing particles
- add missing feature guards in the testsuite
- add subtests to provide more context when a test fails
jngrad added a commit to jngrad/espresso that referenced this issue Jan 19, 2023
Fixes espressomd#4644
Fixes espressomd#4645

Description of changes:
- bugfix: the type map is now properly updated when clearing particles
- add missing feature guards in the testsuite
- add subtests to provide more context when a test fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant