Trying to run openMC on a fresh ubuntu install under WSL (performed all steps in the dockerfile to install openMC).
running the pincell example gives an error related to the lxml package (seems to be an issue with the way lxml is called):
Traceback (most recent call last):
File "build_xml.py", line 56, in <module>
geometry.export_to_xml()
File "/mnt/c/Users/SOC/Workspace/codes/openmc/openmc/geometry.py", line 98, in export_to_xml
self.root_universe.create_xml_subelement(root_element, memo=set())
File "/mnt/c/Users/SOC/Workspace/codes/openmc/openmc/universe.py", line 578, in create_xml_subelement
cell_element = cell.create_xml_subelement(xml_element, memo)
File "/mnt/c/Users/SOC/Workspace/codes/openmc/openmc/cell.py", line 622, in create_xml_subelement
create_surface_elements(self.region, xml_element, memo)
File "/mnt/c/Users/SOC/Workspace/codes/openmc/openmc/cell.py", line 613, in create_surface_elements
xml_element.append(node.surface.to_xml_element())
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 237, in append
self._assert_is_element(subelement)
File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 259, in _assert_is_element
raise TypeError('expected an Element, not %s' % type(e).__name__)
TypeError: expected an Element, not Element
lxml version: 4.6.3
python version: 3.8.10
Has anyone encountered such an error before, or know a fix?
Hi @SOC and welcome to the community. Based on the traceback, the error is actually occurring in xml.etree.ElementTree, not lxml. Currently, lxml is only used in another part of the code. Are you able to share your Python code (or a minimal example) that demonstrates this error so I can try to reproduce?
Here is a minimal example adapted from the pincell example:
from math import log10
import numpy as np
import openmc
###############################################################################
# Create materials for the problem
helium = openmc.Material(name='Helium for gap')
helium.set_density('g/cm3', 0.001598)
helium.add_element('He', 2.4044e-4)
# Collect the materials together and export to XML
materials = openmc.Materials([helium])
materials.export_to_xml()
###############################################################################
# Define problem geometry
# Create cylindrical surfaces
fuel_or = openmc.ZCylinder(r=0.39218, name='Fuel OR')
clad_ir = openmc.ZCylinder(r=0.40005, name='Clad IR')
clad_or = openmc.ZCylinder(r=0.45720, name='Clad OR')
# Create a region represented as the inside of a rectangular prism
pitch = 1.25984
box = openmc.rectangular_prism(pitch, pitch, boundary_type='reflective')
# Create cells, mapping materials to regions
gap = openmc.Cell(fill=helium, region=+fuel_or & -clad_ir)
# Create a geometry and export to XML
geometry = openmc.Geometry([gap])
geometry.export_to_xml()
Strangely, the material export to xml is working but it is when the geometry is exported that the xml/etree/ElementTree error appeared.
When I try running this code, it seems to work just fine (also on Python 3.8). Could you run pip list in your WSL environment and paste the results here?
I tried to reproduce this environment as closely as I could, but the example script still works with no problems. I do see that you have many packages here that are not necessary for OpenMC. You might want to try creating a new Python virtual environment with just an installation of OpenMC and its dependencies and see if that solves the issue.
Problem has been solved by resetting Ubuntu and installing openmc through Anaconda.
We are not sure what the issue was.
The openmc python package was installed with sudo pip install -e ., (the -e flag does not allow pip to install with --user). this could have caused some issues with conflicting xml packages?
Problem is solved, thank you very much for your time and effort