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

Issue when chaining commands #190

Open
thomasms opened this issue Dec 5, 2023 · 1 comment
Open

Issue when chaining commands #190

thomasms opened this issue Dec 5, 2023 · 1 comment

Comments

@thomasms
Copy link

thomasms commented Dec 5, 2023

Using U235 from ENDF-B-VIII.0 (n-092_U_235.endf) with the njoy file below I notice some issues when trying to parse the output (tape50) in ENDFtk.

moder
20 -30
reconr
-30 -21 /
'reconstructed u235' /
9228 /
0.001 /
0 /
broadr
-30 -21 -22
9228 /
0.01 /
300 /
0 /
heatr
-30 -22 -23 0 /
9228 3 /
302 318 402 /
moder
-23 50
stop

It seems strange to me, although perhaps I have made a mistake :), that the following produces a seg fault.

import ENDFtk as tk
x = tk.tree.Tape.from_file('./tape50').materials.front().section(3,2).parse()

whereas doing this in the more verbose way as below, produces no error.

import ENDFtk as tk

tape = tk.tree.Tape.from_file('./tape50')
mat = tape.materials.front()
mf3_mt2 = mat.section(3, 2).parse()
print(mf3_mt2.energies.to_list())

Note my system is: python3.11 with ENDFtk compiled from source on Ubuntu 20.04 with gcc 9.4.0.

Am I misunderstanding the ENDFtk API or could this be a bug?

@whaeck
Copy link
Member

whaeck commented Dec 5, 2023

This seems to be an issue with the garbage collection in python.

The tk.tree.Tape.from_file('./tape50') command returns a newly constructed object (there is no "owner" of this object to keep a reference to it). Since commands are being chained onto it, a handle to it was never stored. I assume the garbage collector just cleaned it up.

I'm looking through the pybind11 documentation to see if there is anything I can do to resolve this. However, I think the best solution in this case is to just not chain from what is a newly created object that has no reference on the C++ side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants