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

Simulation refactor #586

Open
wants to merge 115 commits into
base: develop
Choose a base branch
from
Open

Simulation refactor #586

wants to merge 115 commits into from

Conversation

christophwelling
Copy link
Collaborator

This is the refactor of the simulation.py script:

  • Simulations are split up between classes that handle the simulation at station, event and shower level
  • Writing the output is handled by its own class
  • Passing information around using member variables is gone. Only exceptions are the methods set_event_group and set_event.
    I'm going to write some documentation about how this is supposed to work once the documentation builds properly again.

@sjoerd-bouma
Copy link
Collaborator

@christophwelling Haven't had a proper look at this yet, but it's probably worth merging in the latest develop - the tests (including the documentation) should complete successfully on those.

@christophwelling
Copy link
Collaborator Author

The tests seem to work, but the documentation fails because of some class for ARA.

@sjoerd-bouma
Copy link
Collaborator

I don't think the ARA import is what breaks the documentation, but I'll take full responsibility for the documentation script somehow still being unable to properly sort the error messages. These are errors that should actually be fixed:

/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of set_shower in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/channel_efield_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of set_shower in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/channel_efield_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of set_event_group in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of set_event_group in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station_per_shower in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station_per_shower in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: Unknown section Parameters: in the docstring of add_station_per_shower in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/output_writer_hdf5.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: potentially wrong underline length... 
Parameters 
----------- in 
Set information about the station that is currently simulated.
... in the docstring of set_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/shower_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: potentially wrong underline length... 
Parameters 
----------- in 
Set information about the station that is currently simulated.
... in the docstring of set_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/shower_simulator.py.
  warn(msg)
/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/site-packages/numpydoc/docscrape.py:460: UserWarning: potentially wrong underline length... 
Parameters 
----------- in 
Set information about the station that is currently simulated.
... in the docstring of set_station in /home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/shower_simulator.py.
  warn(msg)
WARNING: autodoc: failed to import module 'generate_unforced' from module 'NuRadioMC.EvtGen'; the following exception was raised:
No module named 'NuRadioMC.simulation.simulation_base'
/home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py:docstring of NuRadioMC.simulation.hardware_response_simulator.hardwareResponseSimulator.simulate_detector_response:7: ERROR: Unexpected indentation.
/home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py:docstring of NuRadioMC.simulation.hardware_response_simulator:4: WARNING: Block quote ends without a blank line; unexpected unindent.
/home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py:docstring of NuRadioMC.simulation.hardware_response_simulator.hardwareResponseSimulator:1: WARNING: Definition list ends without a blank line; unexpected unindent.
/home/runner/work/NuRadioMC/NuRadioMC/NuRadioMC/simulation/hardware_response_simulator.py:docstring of NuRadioMC.simulation.hardware_response_simulator.hardwareResponseSimulator.simulate_detector_response:16: ERROR: Unexpected indentation.

Looks like one missing module (simulation_base), and some sections named Parameters: instead of Parameters. The underlines should be the same length as the section headings.

@fschlueter
Copy link
Collaborator

fschlueter commented Nov 22, 2023

@christophwelling, what I can already say is that the branch is not compatible with numpy==1.24 which removed all aliases for built-in data types. I think it makes sense to already fix it here. They were already labeled deprecated with 1.20
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

@fschlueter
Copy link
Collaborator

I understand that you probably wanted to first just refactor the code without changing the functionality. However, should we not also cut "loose ends"? E.g.,

        if default_detector_station is not None:
            logger.warning(
                'Deprecation warning: Passing the default detector station is deprecated. Default stations and default'
                'channel should be specified in the detector description directly.'
            )
            logger.status(f"Default detector station provided (station {default_detector_station}) -> Using generic detector")
            self._det = NuRadioReco.detector.generic_detector.GenericDetector(json_filename=self._detectorfile, default_station=default_detector_station,
                                                 default_channel=default_detector_channel, antenna_by_depth=False)
        else:

@fschlueter
Copy link
Collaborator

The new "subclasses" like hardwareResponseSimulator do not log any information, warnings, .... . Is that correct?

@sjoerd-bouma
Copy link
Collaborator

I understand that you probably wanted to first just refactor the code without changing the functionality. However, should we not also cut "loose ends"? E.g.,

        if default_detector_station is not None:
            logger.warning(
                'Deprecation warning: Passing the default detector station is deprecated. Default stations and default'
                'channel should be specified in the detector description directly.'
            )
            logger.status(f"Default detector station provided (station {default_detector_station}) -> Using generic detector")
            self._det = NuRadioReco.detector.generic_detector.GenericDetector(json_filename=self._detectorfile, default_station=default_detector_station,
                                                 default_channel=default_detector_channel, antenna_by_depth=False)
        else:

I believe we haven't yet had a full release with this deprecation warning included, so I think we should keep it for 2.2.0 and only fully deprecate it in a future version.

@sjoerd-bouma sjoerd-bouma mentioned this pull request Nov 24, 2023
4 tasks
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

Successfully merging this pull request may close these issues.

None yet

3 participants