ukaea/neutronics_material_maker

Setup issues

CoronelBuendia opened this issue · 14 comments

setup.py should read:
packages['neutronics_material_maker'],

__init__.py should perhaps be empty and have one in every folder? At the moment a fresh clone and python setup.py install is raising circular dependencies in the __init__.py file.

element.py:
NameError: name 'find_protons_from_symbol' is not defined

Thanks for these suggestions.

The init files have bee changed

I've fixed the circular reference issue for isotopes, elements and compounds. I shall do materials and homogeneous mixtures tomorrow

Traceback (most recent call last):

  File "<ipython-input-1-068ffc67bc53>", line 1, in <module>
    import neutronics_material_maker as nmm

  File "/home/mc2056/anaconda3/lib/python3.6/site-packages/neutronics_material_maker/__init__.py", line 20, in <module>
    from .isotope import Isotope

  File "/home/mc2056/anaconda3/lib/python3.6/site-packages/neutronics_material_maker/isotope.py", line 8, in <module>
    from common_utils import natural_abundance

ModuleNotFoundError: No module named 'common_utils'

I just made a fresh Docker Python 3 and pip3 image to test the pip install and spotted that I had a few incorrect import statements , these were working on my regular system somehow. I have now changed the imports and it should be fixed now, let me know if it works for you

I have now hooked up Travis CI so that all git pushes are now tested. I can see from the Travis page that the current master and dev branch are passing the tests

Great stuff - working now. Good job on the CI!

OK, so the pip install is fine - no problems there. But then I wanted to fiddle with some bits of the source, so uninstalled the pip install and did a local clone + python setup.py develop.

The from neutronics_material_maker.X import x formulation no longer works if I do this.

I've never set something up on a pip install, and I have never put anything in the __init__.py files, so I'm not sure how this should be done properly... All I know is that if I use from X import x within the package it works fine.

Maybe relative imports will solve this for both the external user (pip) and the developer (clone+python setup.py develop). E.g. from . import Isotope

When I work locally I was just installing with this command and the force option

python setup.py install -f

then and import statement such as
from neutronics_material_maker import *
or
import neutronics_material_maker as nmm
or
from neutronics_material_maker import Isotope
or
from neutronics_material_maker.isotope import Isotope

Tried full fresh install, clone and python setup.py install -f /--force and none of those lines above work
import neutronics_material_maker is the only thing that goes, and the only things the dot operator will work on there are neutronics_material_maker and setup.py.

I think the problem may come from setup.py where you define name = 'neutronics_material_maker' and packages = ['neutronics_material_maker']. I think this is giving python a namespace conflict and it is pointing to the global folder rather than the sub folder with the same name. I'm gonna submit a pull request for the verbosity thing, but it will have all the import fixes for python setup.py develop as well... Sorry!

I think you have been abusing the "dot"

in my books, nmm shouldn't have any of these classes/functions.. normally i would do something like:
nmm.common_utils.all_natural_elements()
I think you might have been giving nmm all these things in your init file... not sure.. will keep investigating

It goes without saying: just because I do it this way, dont mean it's right... I have no formal training in this crap. Trust Tom!

RROR: test_all_elements_have_natural_isotope_fractions_summing_to_1 (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 161, in test_all_elements_have_natural_isotope_fractions_summing_to_1
    all_elements = nmm.all_natural_elements()
AttributeError: module 'neutronics_material_MAKER' has no attribute 'all_natural_elements'
======================================================================
ERROR: test_all_natural_elements (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 137, in test_all_natural_elements
    all_elements = nmm.all_natural_elements_symbols()
AttributeError: module 'neutronics_material_MAKER' has no attribute 'all_natural_elements_symbols'
======================================================================
ERROR: test_atomic_number (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 29, in test_atomic_number
    new_isotope = nmm.Isotope('Li',7)
AttributeError: module 'neutronics_material_MAKER' has no attribute 'Isotope'
======================================================================
ERROR: test_broken_element (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 126, in test_broken_element
    z = nmm.Compound('zzzz', density_g_per_cm3=1)
AttributeError: module 'neutronics_material_MAKER' has no attribute 'Compound'
======================================================================
ERROR: test_compound_chemical_equation (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 62, in test_compound_chemical_equation
    new_compound = nmm.Compound('Li4SiO4')
AttributeError: module 'neutronics_material_MAKER' has no attribute 'Compound'
======================================================================
ERROR: test_compound_enriched_isotopes (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 70, in test_compound_enriched_isotopes
    new_compound = nmm.Compound('Li4SiO4',enriched_isotopes=(nmm.Isotope('Li', 6, 0.9), nmm.Isotope('Li', 7, 0.1)))
AttributeError: module 'neutronics_material_MAKER' has no attribute 'Compound'
======================================================================
ERROR: test_compound_enriched_isotopes_natural (neutronics_material_MAKER.tests.module_tests.Tester)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/ukaea/neutronics_material_maker/neutronics_material_MAKER/tests/module_tests.py", line 66, in test_compound_enriched_isotopes_natural
    new_compound = nmm.Compound('Li4SiO4')
AttributeError: module 'neutronics_material_MAKER' has no attribute 'Compound'

OK so the __init__.py imports you allow you to hack the dot... I am still distrustful of this behaviour, but I put back the import in the init so it should work as you are used to ;)

Do you have the folder in your sys path as well as your /usr/local/lib/python
Perhaps this is causing naming conflict

import sys
sys.path
sys.path.remove(' path to neutronics material maker')

I have recoded parts of the material maker and I think the imports are finally improved

from neutronics_material_maker.nmm import *

This is on a new branch called recode, also I have made a few more changes

the init file is now empty as suggested,
color is accepted by Compounds, Materials, Homogenised_materials, Isotopes and Elements
xsdir files names can be found for each isotope (requested to reduce the quantity of nuc data on the Docker image)

One change that might change general usage is the creation of Materials is no longer done by passing one of several recognized description strings. Now Materials are made with lists of elements. Sorry for this inconvenience, I have made all the same materials (Eurofer, Tungsten etc) in the examples.py file so they can be imported and used as normal.

Hey, can you push it? I can't see recode - only "rewrite" and that was last updated 13 days ago :)

Ah , I think I might have pushed to master. Sorry. I haven't updated the pip install yet.