neams-th-coe / cardinal

High-Fidelity Multiphysics
https://cardinal.cels.anl.gov/
Other
84 stars 39 forks source link

Unable to run OpenMC with Python API from Cardinal #909

Closed naheed23 closed 1 month ago

naheed23 commented 1 month ago

I recently installed Cardinal for work. Currently, I am trying to run OpenMC using Python files, but it's not working like it should. I built Cardinal with MOOSE's conda environment, which was successful. Under "Checking the Install" (https://cardinal.cels.anl.gov/with_conda.html#running), I was successfully able to run #1. However, for #2 (the one I prefer and need for the moment), when I try to execute the provided Python file, I get this error:

Traceback (most recent call last): File "/.../.../cardinal/tutorials/lwr_solid/make_openmc_model.py", line 19, in import openmc ModuleNotFoundError: No module named 'openmc'

Which, of course, indicates that my Python/Conda environment does not have OpenMC. (I have ran this code a few time times and got the same error every time). I am unsure what to do, because I don't think it would be wise to make a separate installation of OpenMC just to get the Python API to work properly, considering that #2 on checking the install implies that it should work without additional steps.

Are there some instructions I am missing to get the Python API to work properly within Cardinal? Or do I have to make separate installations (https://docs.openmc.org/en/stable/usersguide/install.html#installing-python-api)? As stated in the first sentence, this is important for my work. It's not urgent yet, but soon will be.

nuclearkevin commented 1 month ago

You can install the OpenMC python interface by navigating to contrib/openmc and running python -m pip install .. This will use Cardinal's OpenMC dependency to install the python bindings. Afterwards, you should be able to run the generator script for the pincell.

At the moment make_openmc_model.py will throw an error as the tutorial hasn't been updated to account for a version change in OpenMC. I'm working on a PR to update the tutorials, but in the meantime you can change

box = openmc.rectangular_prism(pitch, pitch, boundary_type='reflective')

to the following:

box = openmc.model.rectangular_prism(pitch, pitch, boundary_type='reflective')

as a quick fix.

aprilnovak commented 1 month ago

Thanks @nuclearkevin! And yes @naheed23, the instructions for doing this are listed on the Cardinal website, but I've updated that page to make it a bit more obvious.

cd cardinal/contrib/openmc
pip install .