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

Roll out ScriptInterface #4541

Merged
merged 23 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fdcd991
python: Use consistent variable types
jngrad Jul 14, 2022
4a5c3a7
python: Improve type safety, use keyword arguments
jngrad Jul 14, 2022
3f93aa1
script_interface: Cleanup
jngrad Jul 14, 2022
42ad39a
script_interface: Modernize interface code
jngrad Jul 15, 2022
bb36893
python: Break circular dependency
jngrad Jul 15, 2022
59b47c0
script_interface: Rewrite Analysis module
jngrad Jul 19, 2022
5add7f8
script_interface: Rewrite System module
jngrad Jul 19, 2022
b82a695
script_interface: Rewrite ObservableStat
jngrad Jul 20, 2022
6f34349
script_interface: Rewrite Galilei module
jngrad Jul 20, 2022
47c3d69
script_interface: Rewrite CellSystem module
jngrad Jul 20, 2022
ceb7ed7
script_interface: Rewrite ComFixed module
jngrad Jul 20, 2022
a7be062
script_interface: Move CTP to math submodule
jngrad Jul 20, 2022
74ec1fe
script_interface: Rewrite ParticleHandle
jngrad Jul 22, 2022
dd90d0e
script_interface: Rewrite ParticleList
jngrad Jul 22, 2022
0cc3b59
script_interface: Rewrite ParticleSlice
jngrad Jul 22, 2022
45054fe
script_interface: Rewrite Polymer module
jngrad Jul 22, 2022
d1ea885
doc: Fix Sphinx regressions in generated methods
jngrad Jul 22, 2022
2111342
config: Rewrite config generation script
jngrad Jul 28, 2022
b6b36d0
script_interface: Rewrite code_info module
jngrad Aug 1, 2022
1eaa7a6
script_interface: Rewrite version module
jngrad Aug 2, 2022
606247d
script_interface: Rewrite cuda_init module
jngrad Aug 2, 2022
bba0681
Merge branch 'python' into refactor_cython
jngrad Aug 5, 2022
1fba163
script_interface: Fix regressions revealed by CI
jngrad Aug 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/sphinx/integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ The following minimal example illustrates how to use the SDM in |es|::
system.periodicity = [False, False, False]
system.time_step = 0.01
system.cell_system.skin = 0.4
system.part.add(pos=[0, 0, 0], rotation=[1, 0, 0])
system.part.add(pos=[0, 0, 0], rotation=[True, False, False])
system.integrator.set_stokesian_dynamics(viscosity=1.0, radii={0: 1.0})
system.integrator.run(100)

Expand Down Expand Up @@ -690,7 +690,7 @@ needs to be activated via::
system.periodicity = [False, False, False]
system.time_step = 0.01
system.cell_system.skin = 0.4
system.part.add(pos=[0, 0, 0], rotation=[1, 0, 0], ext_force=[0, 0, -1])
system.part.add(pos=[0, 0, 0], rotation=[True, False, False], ext_force=[0, 0, -1])
system.thermostat.set_stokesian(kT=1.0, seed=43)
system.integrator.set_stokesian_dynamics(viscosity=1.0, radii={0: 1.0})
system.integrator.run(100)
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx/magnetostatics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ Magnetostatic interactions are activated via the actor framework::

system = espressomd.System(box_l=[10, 10, 10])
system.time_step = 0.01
system.part.add(pos=[[0, 0, 0], [1, 1, 1]],
rotation=2 * [(1, 1, 1)], dip=2 * [(1, 0, 0)])
system.part.add(pos=[[0, 0, 0], [1, 1, 1]], dip=2 * [(1, 0, 0)],
rotation=2 * [(True, True, True)])

actor = espressomd.magnetostatics.DipolarDirectSumCpu(prefactor=1.)
system.actors.add(actor)
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/particles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ Lattice-Boltzmann swimmers

import espressomd
system = espressomd.System(box_l=[1, 1, 1])
system.part.add(pos=[2, 0, 0], rotation=[1, 1, 1], swimming={
system.part.add(pos=[2, 0, 0], rotation=[True, True, True], swimming={
'f_swim': 0.01, 'mode': 'pusher', 'dipole_length': 2.0})

For an explanation of the parameters ``v_swim`` and ``f_swim`` see the previous
Expand Down
4 changes: 2 additions & 2 deletions doc/sphinx/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ feature)::

for i in range(10):
system.part.add(pos=np.random.random(3) * box_l,
rotation=[1, 1, 1],
rotation=[True, True, True],
ext_torque=[5, 0, 0],
v=[10, 0, 0],
type=0)
system.part.add(pos=np.random.random(3) * box_l,
rotation=[1, 1, 1],
rotation=[True, True, True],
ext_torque=[0, 5, 0],
v=[-10, 0, 0],
type=1)
Expand Down
3 changes: 2 additions & 1 deletion doc/tutorials/ferrofluid/ferrofluid_part1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@
"outputs": [],
"source": [
"# Add particles\n",
"system.part.add(pos=pos, rotation=N_PART * [(1, 1, 1)], dip=dip, fix=N_PART * [(0, 0, 1)])"
"system.part.add(pos=pos, rotation=N_PART * [(True, True, True)],\n",
" dip=dip, fix=N_PART * [(False, False, True)])"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion maintainer/benchmarks/ferrofluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
#############################################################
system.part.add(
pos=np.random.random((n_part, 3)) * system.box_l,
rotation=n_part * [(1, 1, 1)],
rotation=n_part * [(True, True, True)],
dipm=n_part * [args.dipole_moment])

# Warmup Integration
Expand Down
6 changes: 4 additions & 2 deletions maintainer/benchmarks/lj.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@
system.bonded_inter.add(hb)
for _ in range(0, n_part, 2):
pos = np.random.random(3) * system.box_l
vec = np.random.random(3)
vec /= np.linalg.norm(vec)
p1 = system.part.add(pos=pos)
p2 = system.part.add(pos=pos + np.random.random(3) / np.sqrt(3))
system.part[p1].add_bond((hb, p2))
p2 = system.part.add(pos=pos + vec * hb.r_0)
p1.add_bond((hb, p2))

# Warmup Integration
#############################################################
Expand Down
6 changes: 3 additions & 3 deletions samples/dancing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
system.integrator.set_stokesian_dynamics(
viscosity=1.0, radii={0: 1.0}, approximation_method=sd_method)

system.part.add(pos=[-5, 0, 0], rotation=[1, 1, 1])
system.part.add(pos=[0, 0, 0], rotation=[1, 1, 1])
system.part.add(pos=[7, 0, 0], rotation=[1, 1, 1])
system.part.add(pos=[-5, 0, 0], rotation=[True, True, True])
system.part.add(pos=[0, 0, 0], rotation=[True, True, True])
system.part.add(pos=[7, 0, 0], rotation=[True, True, True])

gravity = espressomd.constraints.Gravity(g=[0, -1, 0])
system.constraints.add(gravity)
Expand Down
2 changes: 1 addition & 1 deletion samples/drude_bmimpf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def combination_rule_sigma(rule, sig1, sig2):
cation_com = system.part.add(
type=types["BMIM_COM"], pos=pos_com,
mass=masses["BMIM_COM"], rinertia=[646.284, 585.158, 61.126],
gamma=0, rotation=[1, 1, 1])
gamma=0, rotation=[True, True, True])

cation_c1 = system.part.add(type=types["BMIM_C1"],
pos=pos_com + [0, -0.527, 1.365], q=charges["BMIM_C1"])
Expand Down
2 changes: 1 addition & 1 deletion samples/grand_canonical.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
reactant_types=[], reactant_coefficients=[], product_types=[1, 2],
product_coefficients=[1, 1], default_charges={1: -1, 2: +1})
print(RE.get_status())
system.setup_type_map([0, 1, 2])
system.setup_type_map(type_list=[0, 1, 2])

# Set the hidden particle type to the lowest possible number to speed
# up the simulation
Expand Down
4 changes: 2 additions & 2 deletions samples/lj_liquid_structurefactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
structurefactor_type_list = [0, 1]
structurefactor_order = 20
structurefactor_bins = len(system.analysis.structure_factor(
[0], structurefactor_order)[0])
sf_types=[0], sf_order=structurefactor_order)[0])
structurefactor_k = np.zeros(structurefactor_bins)
structurefactor_Sk = np.zeros(structurefactor_bins)

Expand Down Expand Up @@ -153,7 +153,7 @@
system.integrator.run(int_steps)

structurefactor_k, structurefactor_Sk = system.analysis.structure_factor(
structurefactor_type_list, structurefactor_order)
sf_types=structurefactor_type_list, sf_order=structurefactor_order)

energies = system.analysis.energy()
print(energies['total'])
Expand Down
2 changes: 1 addition & 1 deletion samples/reaction_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
assert RE is not None, "Please choose a reaction ensemble from the command line"

print(RE.get_status())
system.setup_type_map(list(types.values()))
system.setup_type_map(type_list=list(types.values()))


# Set the hidden particle type to the lowest possible number to speed
Expand Down
3 changes: 2 additions & 1 deletion samples/rigid_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def rotate_vector(vector, axis, angle):
# place center bead
p_center = system.part.add(
pos=center_of_mass, mass=branch_len * 6 + 1, rinertia=principal_moments,
rotation=[1, 1, 1], type=ParticleTypes.CENTER.value, quat=espressomd.rotation.matrix_to_quat(principal_axes))
rotation=[True, True, True], type=ParticleTypes.CENTER.value,
quat=espressomd.rotation.matrix_to_quat(principal_axes))

# Relate the particles that make up the rigid body to the central particle.
# This will also mark them as `virtual = True`
Expand Down
2 changes: 1 addition & 1 deletion samples/widom_insertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
reactant_coefficients=[], product_types=[1, 2],
product_coefficients=[1, 1], default_charges={1: -1, 2: +1})
print(widom.get_status())
system.setup_type_map([0, 1, 2])
system.setup_type_map(type_list=[0, 1, 2])


# Set the hidden particle type to the lowest possible number to speed
Expand Down
139 changes: 80 additions & 59 deletions src/config/gen_featureconfig.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#
# Copyright (C) 2013-2022 The ESPResSo project
# Copyright (C) 2012 Olaf Lenz
#
Expand All @@ -16,9 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This script generates the files featureconfig.h and featureconfig.c.
#
import time

import string
import inspect
import sys
Expand All @@ -32,67 +31,78 @@
print(f"Usage: {sys.argv[0]} DEFFILE HPPFILE CPPFILE", file=sys.stderr)
exit(2)

deffilename, hfilename, cfilename = sys.argv[1:5]

print("Reading definitions from " + deffilename + "...")
defs = featuredefs.defs(deffilename)
print("Done.")

print("Writing " + hfilename + "...")
hfile = open(hfilename, 'w')

hfile.write("""/*
WARNING: This file was autogenerated by
path_def, path_hpp, path_cpp = sys.argv[1:5]

%s on %s
print(f"Reading definitions from {path_def}")
defs = featuredefs.defs(path_def)

Do not modify it or your changes will be overwritten!
Modify features.def instead.
disclaimer = f"""/*
WARNING: This file was generated automatically.
Do not modify it or your changes will be overwritten!
Modify features.def instead.
*/
#ifndef ESPRESSO_FEATURECONFIG_HPP
#define ESPRESSO_FEATURECONFIG_HPP

#include "cmake_config.hpp"
#include "myconfig-final.hpp"
"""

""" % (sys.argv[0], time.asctime()))
print(f"Writing {path_hpp}")
hfile = open(path_hpp, 'w')
hfile.write(disclaimer)
hfile.write("""
#ifndef ESPRESSO_SRC_CONFIG_CONFIG_FEATURES_HPP
#define ESPRESSO_SRC_CONFIG_CONFIG_FEATURES_HPP
""")

# external features can only be set by the build
# system, so in case the user has defined some of
# them, we undef all external features and include
# the config from the build system again, to make
# sure only the detected ones are set.
hfile.write('/* Guards for externals */')
hfile.write("""
/*********************************/
/* Handle definitions from CMake */
/*********************************/

#include "cmake_config.hpp"
#include "myconfig-final.hpp"
""")
external_template = string.Template("""
// $feature is external
#if defined($feature)
#undef $feature
#endif
""")
for feature in defs.externals:
for feature in sorted(defs.externals):
hfile.write(external_template.substitute(feature=feature))

# Include definitions from CMake
hfile.write("""
/* Definitions from CMake */
#include "cmake_config.hpp"

""")

# handle implications
hfile.write('/* Handle implications */')
hfile.write("""\
/***********************/
/* Handle implications */
/***********************/
""")
implication_template = string.Template("""
// $feature implies $implied
#if defined($feature) && !defined($implied)
#define $implied
#endif
""")
for feature, implied in defs.implications:
for feature, implied in sorted(defs.implications):
hfile.write(implication_template.substitute(
feature=feature, implied=implied))

hfile.write("\n")

# output warnings if internal features are set manually
hfile.write('/* Warn when derived switches are specified manually */')
hfile.write("""\
/*****************************************************/
/* Warn when derived switches are specified manually */
/*****************************************************/
""")
derivation_template = string.Template("""
// $feature equals $expr
#ifdef $feature
Expand All @@ -101,58 +111,52 @@
#define $feature
#endif
""")
for feature, expr, cppexpr in defs.derivations:
for feature, expr, cppexpr in sorted(defs.derivations):
hfile.write(derivation_template.substitute(
feature=feature, cppexpr=cppexpr, expr=expr))

# write footer
# define external FEATURES and NUM_FEATURES
hfile.write("""
extern const char* FEATURES[];
extern const int NUM_FEATURES;

#endif /* of _FEATURECONFIG_HPP */""")
hfile.close()
print("Done.")
extern char const *const FEATURES[];
extern char const *const FEATURES_ALL[];
extern unsigned int const NUM_FEATURES;
extern unsigned int const NUM_FEATURES_ALL;

print("Writing " + cfilename + "...")
cfile = open(cfilename, 'w')

# handle requirements

cfile.write(f"""/*
WARNING: This file was autogenerated by
#endif
""")

{sys.argv[0]}
on
{time.asctime()}
hfile.close()

Do not modify it or your changes will be overwritten!
Modify features.def instead.
*/
print(f"Writing {path_cpp}")
cfile = open(path_cpp, "w")

/* config.hpp includes config-features.hpp and myconfig.hpp */
cfile.write(disclaimer)
cfile.write(f"""
#include "config-features.hpp"
#include "config.hpp"

/***********************/
/* Handle requirements */
/***********************/
""")

cfile.write('/* Handle requirements */')

requirement_string = """
// {feature} requires {expr}
#if defined({feature}) && !({cppexpr})
#error Feature {feature} requires {expr}
#endif
"""
for feature, expr, cppexpr in defs.requirements:
for feature, expr, cppexpr in sorted(defs.requirements):
cfile.write(
requirement_string.format(
feature=feature, cppexpr=cppexpr, expr=expr))

cfile.write("""

/****************/
/* Feature list */
const char* FEATURES[] = {
/****************/

char const *const FEATURES[] = {
""")

feature_string = """
Expand All @@ -161,14 +165,31 @@
#endif
"""

for feature in defs.externals.union(defs.features, defs.derived):
for feature in sorted(defs.externals.union(defs.features, defs.derived)):
cfile.write(feature_string.format(feature=feature))

cfile.write("""
};
unsigned int const NUM_FEATURES = sizeof(FEATURES) / sizeof(char*);
""")

const int NUM_FEATURES = sizeof(FEATURES)/sizeof(char*);
cfile.write("""
/*********************/
/* Feature full list */
/*********************/

char const *const FEATURES_ALL[] = {\
""")

feature_string = """
"{feature}","""

for feature in sorted(defs.allfeatures):
cfile.write(feature_string.format(feature=feature))

cfile.write("""
};
unsigned int const NUM_FEATURES_ALL = sizeof(FEATURES_ALL) / sizeof(char*);
""")

cfile.close()
print("Done.")
Loading