-
Notifications
You must be signed in to change notification settings - Fork 37
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
Valgrind findings #8
Comments
Running the In g4.G4Random.setTheSeeds(self.actual_random_seed, 0) where According to the binding in pyRandomize.cpp:28, py::class_<HepRandom>(m, "G4Random")
// other def's ...
.def("setTheSeeds", &HepRandom::setTheSeeds); this calls the following C++ function in CLHEP's void HepRandom::setTheSeeds(const long* seeds, int aux)
{
theDefaults().theEngine->setSeeds(seeds,aux);
} Note that the first argument has the C++ type I don't know whether the pybind11 documentation specifies how it maps the Python integer into a C++ |
Possible fix: gam-g4: diff --git a/gam_g4/g4_bindings/pyRandomize.cpp b/gam_g4/g4_bindings/pyRandomize.cpp
index 7936b98..4df7ece 100644
--- a/gam_g4/g4_bindings/pyRandomize.cpp
+++ b/gam_g4/g4_bindings/pyRandomize.cpp
@@ -25,7 +25,7 @@ void init_Randomize(py::module &m) {
.def("setTheEngine", &HepRandom::setTheEngine)
.def("showEngineStatus", &HepRandom::showEngineStatus)
.def("getTheSeed", &HepRandom::getTheSeed)
- .def("setTheSeeds", &HepRandom::setTheSeeds);
+ .def("setTheSeed", &HepRandom::setTheSeed);
py::class_<HepRandomEngine>(m, "HepRandomEngine"); gam-gate: diff --git a/gam_gate/Simulation.py b/gam_gate/Simulation.py
index 9df0be3..b5d67fd 100644
--- a/gam_gate/Simulation.py
+++ b/gam_gate/Simulation.py
@@ -279,7 +279,7 @@ class Simulation:
self.actual_random_seed = self.user_info.random_seed
# set the seed
- g4.G4Random.setTheSeeds(self.actual_random_seed, 0)
+ g4.G4Random.setTheSeed(self.actual_random_seed, 0)
def initialize_g4_verbose(self):
# For a unknow reason, when verbose_level == 0, there are some Alternatively, if the setTheSeeds functionality must be accessible, pybind11 can automatically convert a Python list into a C++ |
Another error comes up in e.g. The problem in diff --git a/gam_g4/g4_bindings/pyG4RegionStore.cpp b/gam_g4/g4_bindings/pyG4RegionStore.cpp
index d71aead..a0aebe4 100644
--- a/gam_g4/g4_bindings/pyG4RegionStore.cpp
+++ b/gam_g4/g4_bindings/pyG4RegionStore.cpp
@@ -20,5 +20,5 @@ void init_G4RegionStore(py::module &m) {
.def("Get", [](G4RegionStore *r, int i) { return (*r)[i]; }, py::return_value_policy::reference)
.def("GetInstance", &G4RegionStore::GetInstance, py::return_value_policy::reference)
.def("GetRegion", &G4RegionStore::GetRegion, py::return_value_policy::reference)
- .def("FindOrCreateRegion", &G4RegionStore::FindOrCreateRegion);
+ .def("FindOrCreateRegion", &G4RegionStore::FindOrCreateRegion, py::return_value_policy::reference);
} With this change, Python will not take ownership of the G4Region* G4RegionStore::FindOrCreateRegion(const G4String& name) and will therefore not garbage collect it when the returned object is not referenced any more from the Python side. In turn the suggested change makes memory leaks more likely. I'm wondering if the |
See OpenGATE#8 . The C++ code for HepRandom::setTheSeeds expects an array of seeds. If we pass a single number on the Python side, the C++ code accesses memory that was not (intentionally) initialized.
In this issue I'd like to collect findings from applying valgrind to the Python interpreter while it loads and uses the
gam-gate
andgam-g4
modules.This continues OpenGATE/Gate#480.
My current procedure (for the record)
Setup singularity container, download and build Geant4 etc.:
First clone
gate-singularity
and checkout thegam
branch (commit eeb1ca2d), build the Singularity image, and inside the Singularity container, download/build GATE and its dependencies. This is described in more detail in theREADME.md
. Exit and restart the container to update the environment.gam-g4:
As described in the gam-gate
readme.md
,in order to create the Python module
/software/gam-g4/gam_g4/gam_g4.cpython-36m-x86_64-linux-gnu.so
. Exit and restart the container to update the environment.gam-gate:
Then build the Python module
gam-gate
viagatetools:
In addition to the gam-gate
readme.md
, we need the latestgatetools
package for Python:run tests:
Now we can run the individual tests, e.g.
To run with valgrind, e.g.
The text was updated successfully, but these errors were encountered: