fusion-energy / openmc-plasma-source

Creates a plasma source as an openmc.source object from input parameters that describe the plasma
MIT License
25 stars 11 forks source link

tests are failing on main and develop #64

Closed shimwell closed 1 year ago

shimwell commented 1 year ago

Just running the tests on the main or develop branch and I am seeing this error and getting one failing test

    @given(tokamak_source=tokamak_source_strategy())
    @settings(max_examples=50)
    def test_strengths_are_normalised(tokamak_source):
        """Tests that the sum of the strengths attribute is equal to"""
>       assert pytest.approx(sum(tokamak_source.strengths)) == 1
E       assert nan ± ??? == 1
E         comparison failed
E         Obtained: 1
E         Expected: nan ± ???
E       Falsifying example: test_strengths_are_normalised(
E           tokamak_source=TokamakSource(angles=(0, 6.283185307179586), elongation=1.0, ion_density_centre=1.09e+20, ion_density_peaking_factor=1, ion_density_pedestal=1.09e+20, ion_density_separatrix=3e+19, ion_temperature_beta=6, ion_temperature_centre=45.9, ion_temperature_peaking_factor=8.06, ion_temperature_pedestal=6.09, ion_temperature_separatrix=0.1, major_radius=1.0, minor_radius=1.5258789062500003e-05, mode='H', name='TokamakSource', pedestal_radius=1.52587890625e-05, sample_size=1000, triangularity=0.0),
E       )
RemDelaporteMathurin commented 1 year ago

I'll look into it

shimwell commented 1 year ago

When running these tests I am using the latest version of openmc. This could be the difference so I've made PR #65

RemDelaporteMathurin commented 1 year ago

Is it failing in the CI too? cause the config.yml file for circleci has openmc 0.12.2 https://github.com/fusion-energy/openmc-plasma-source/blob/15c2194c1f386bf60514dde6797545f6615a1605/.circleci/config.yml#L6

RemDelaporteMathurin commented 1 year ago

@shimwell it cannot be the openmc version cause the same behaviour was observed here https://github.com/fusion-energy/openmc-plasma-source/pull/63 and the openmc version was still 0.12.2

This is something else

RemDelaporteMathurin commented 1 year ago

I confirm that I reproduced the bug in the openmc/openmc:v0.12.2 docker image!

RemDelaporteMathurin commented 1 year ago

Little progress on the issue: the test fail when the densities attribute of the TokamakSource object is full of zero values. Therefore, the neutron_source_density attribute is also full of zeros, therefore it's sum is zero.

There's then a division by zero https://github.com/fusion-energy/openmc-plasma-source/blob/f5a24b6e320d4f9b1952bbd5b828507415a42348/openmc_plasma_source/tokamak_source.py#L241 which produces nan.

RemDelaporteMathurin commented 1 year ago

The bug only occurs with mode "H" sources