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

Remove Multiple Inheratince #32

Merged
merged 7 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 2 additions & 64 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Build nuflux with Meson
if: matrix.build == 'meson'
run: |
python3 -m pip install meson numpy sphinx breathe sphinx_rtd_theme pytest pytest-tap
python3 -m pip install meson 'numpy<2' sphinx breathe sphinx_rtd_theme pytest pytest-tap
meson setup build . -D b_coverage=true --prefix=${HOME}/inst/
meson test -C build
- name: Rename TestLog
Expand Down Expand Up @@ -92,71 +92,9 @@ jobs:
run: docs/docs-upload.sh
env:
ICECUBE_PASSWORD: ${{ secrets.ICECUBE_PASSWORD }}
cvmfs_meson_tests:
name: cvmfs meson tests ${{matrix.cvmfs}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cvmfs: [py3-v4.1.1, py3-v4.3.0]
steps:
- uses: cvmfs-contrib/github-action-cvmfs@v3
- name: Checkout nuflux
uses: actions/checkout@v4
- name: Build and Run Tests in Docker
uses: addnab/docker-run-action@v3
with:
options: -v /cvmfs/icecube.opensciencegrid.org/:/cvmfs/icecube.opensciencegrid.org/ -v /home/runner/work/nuflux/nuflux:/nuflux
image: centos:centos7.9.2009
run: |
yum -y install glibc-headers glibc-devel unzip
eval $(/cvmfs/icecube.opensciencegrid.org/${{matrix.cvmfs}}/setup.sh)
unset PYTHONPATH
export PATH=${HOME}/.local/bin:${PATH}
pip install --upgrade --user meson ninja pytest pytest-tap
CMAKE_PREFIX_PATH=${SROOT} BOOST_ROOT=${SROOT} meson setup /nuflux/build /nuflux
meson test -C/nuflux/build
- name: Copy TestLog
if: always()
run: cp -v build/meson-logs/testlog.junit.xml test-results-meson-cvmfs-${{matrix.cvmfs}}.junit.xml
- uses: actions/upload-artifact@v4
if: always()
with:
if-no-files-found: error
name: test-results-meson-cvmfs-${{matrix.cvmfs}}
path: test-results-meson-cvmfs-${{matrix.cvmfs}}.junit.xml
cvmfs_pyproject_tests:
name: cvmfs pyproject tests ${{matrix.cvmfs}}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
cvmfs: [py3-v4.1.1, py3-v4.3.0]
steps:
- uses: cvmfs-contrib/github-action-cvmfs@v3
- name: Checkout nuflux
uses: actions/checkout@v4
- name: Build and Run Tests in Docker
uses: addnab/docker-run-action@v3
with:
options: -v /cvmfs/icecube.opensciencegrid.org/:/cvmfs/icecube.opensciencegrid.org/ -v /home/runner/work/nuflux/nuflux:/nf
image: centos:centos7.9.2009
run: |
yum -y install glibc-headers glibc-devel
eval $(/cvmfs/icecube.opensciencegrid.org/${{matrix.cvmfs}}/setup.sh)
unset PYTHONPATH
python3 -m pip install --upgrade --user pip pytest
BOOST_ROOT=${SROOT} python3 -m pip install --user --verbose /nf
python3 -m pytest /nf --junit-xml=/nf/test-results-pyproject-cvmfs-${{matrix.cvmfs}}.junit.xml
- uses: actions/upload-artifact@v4
if: always()
with:
if-no-files-found: error
name: test-results-pyproject-cvmfs-${{matrix.cvmfs}}
path: test-results-pyproject-cvmfs-${{matrix.cvmfs}}.junit.xml
publish-test-results:
name: "Publish Tests Results"
needs: [Tests, cvmfs_meson_tests, cvmfs_pyproject_tests]
needs: [Tests]
runs-on: ubuntu-latest
permissions:
checks: write
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ repos:
- id: prettier
files: \.ya?ml$
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
rev: v0.5.0
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand All @@ -37,7 +37,7 @@ repos:
- id: forbid-crlf
- id: forbid-tabs
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "A library for calculating atmospheric neutrino fluxes"
readme = "README.md"
requires-python = "~=3.7"
dependencies = ['numpy']
dependencies = ['numpy<2']
license = {file = "LICENSE"}
keywords = ["python", "science", "astronomy", "astrophysics", "IceCube", "atmospheric", "neutrino"]
classifiers = [
Expand Down
23 changes: 22 additions & 1 deletion src/include/nuflux/FluxFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ namespace nuflux{
///The interface for all neutrino fluxes
class FluxFunction{
public:
FluxFunction(std::string name):name(name){}
FluxFunction(std::string name):
name(name),
kneeCorrectionName("none")
{}
virtual ~FluxFunction(){}

std::string getName() const{ return(name); }
Expand All @@ -48,8 +51,16 @@ namespace nuflux{
virtual double getMaxEnergy() const{ return NAN;}
virtual double readExtents(ParticleType type) const{ return NAN;}

virtual void setKneeReweightingModel(std::string reweightModel){
if (reweightModel != "none"){
throw std::runtime_error("This model does not support knee reweighting");
}
}
std::string getKneeReweightingModel() const{ return(kneeCorrectionName); }

protected:
std::string name;
std::string kneeCorrectionName;
};

///Things which are useful or necessary internally for the library but which aren't useful for users
Expand All @@ -75,6 +86,14 @@ namespace nuflux{
};
std::string getDataPath(std::string fname);

void registerKneeModel(const std::string baseModel, const std::string name);

struct KneeRegisterererer{
KneeRegisterererer(const std::string baseModel, const std::string name){
registerKneeModel(baseModel,name);
}
};

} //namespace detail

} //namespace nuflux
Expand All @@ -83,5 +102,7 @@ namespace nuflux{
namespace{ nuflux::detail::FluxRegisterererer BOOST_PP_CAT( registerererer , __LINE__ ) (name,factory); }
#define NNF_REGISTER_DEPRECATED_FLUX(name,factory,reason)\
namespace{ nuflux::detail::FluxRegisterererer BOOST_PP_CAT( registerererer , __LINE__ ) (name,factory,reason); }
#define NNF_REGISTER_KNEE(baseModel,name) \
namespace{ nuflux::detail::KneeRegisterererer BOOST_PP_CAT( registerererer , __LINE__ ) (baseModel,name); }

#endif
58 changes: 0 additions & 58 deletions src/include/nuflux/Interfaces.h

This file was deleted.

17 changes: 14 additions & 3 deletions src/include/nuflux/LegacyConventionalFlux.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace nuflux{

class LegacyConventionalFlux : public FluxFunction, public KneeReweightable, public PionKaonAdjustable{
class LegacyConventionalFlux : public FluxFunction{
public:
class component{
public:
Expand Down Expand Up @@ -84,6 +84,10 @@ namespace nuflux{
std::map<ParticleType,component> components;

kneeSpline kneeCorrection;
///the factor by which to boost the pion decay contribution
double pionAdjust;
///the factor by which to boost the kaon decay contribution
double kaonAdjust;
public:
LegacyConventionalFlux(const std::string& fluxName);
static boost::shared_ptr<FluxFunction> makeFlux(const std::string& fluxName);
Expand All @@ -93,8 +97,15 @@ namespace nuflux{
virtual double getMinEnergy() const;
virtual double getMaxEnergy() const;

virtual void setRelativePionContribution(double adjust);
virtual void setRelativeKaonContribution(double adjust);
///boosts the contribution from pion decays
///\param adjust the factor by which to increase the pion contribution
void setRelativePionContribution(double adjust);
double getRelativePionContribution() const{ return(pionAdjust); }

///boosts the contribution from kaon decays
///\param adjust the factor by which to increase the kaon contribution
void setRelativeKaonContribution(double adjust);
double getRelativeKaonContribution() const{ return(kaonAdjust); }

virtual void setKneeReweightingModel(std::string reweightModel);
};
Expand Down
2 changes: 1 addition & 1 deletion src/include/nuflux/LegacyPromptFlux.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace nuflux{

class LegacyPromptFlux : public FluxFunction, public KneeReweightable{
class LegacyPromptFlux : public FluxFunction{
private:
class component{
private:
Expand Down
2 changes: 1 addition & 1 deletion src/include/nuflux/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nuflux_headers = [
'ANFlux.h', 'Fluxes.h', 'FluxFunction.h',
'Interfaces.h', 'IPLEFlux.h', 'LegacyConventionalFlux.h',
'IPLEFlux.h', 'LegacyConventionalFlux.h',
'LegacyPromptFlux.h', 'nuflux.h',
'SplineFlux2.h', 'SplineFlux.h',
]
Expand Down
1 change: 0 additions & 1 deletion src/include/nuflux/nuflux.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace nuflux{

std::string getDataPath(std::string fname);

#include <nuflux/Interfaces.h>
#include <nuflux/Fluxes.h>

#endif //NEWNUFLUX_H
9 changes: 4 additions & 5 deletions src/library/LegacyConventionalFlux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ namespace nuflux{
}

LegacyConventionalFlux::LegacyConventionalFlux(const std::string& fluxName):
FluxFunction(fluxName),
KneeReweightable("none"),
PionKaonAdjustable(1.0,1.0){
FluxFunction(fluxName)
{
components[NuMu] =readConvComponent(fluxName+"_numu.dat");
components[NuMuBar]=readConvComponent(fluxName+"_numubar.dat");
components[NuE] =readConvComponent(fluxName+"_nue.dat");
components[NuEBar] =readConvComponent(fluxName+"_nuebar.dat");
//this looks dumb but is actually necessary to enforce the continuity constraint
setRelativePionContribution(getRelativePionContribution());
setRelativeKaonContribution(getRelativeKaonContribution());
setRelativePionContribution(1.0);
setRelativeKaonContribution(1.0);
}

boost::shared_ptr<FluxFunction> LegacyConventionalFlux::makeFlux(const std::string& fluxName){
Expand Down
4 changes: 2 additions & 2 deletions src/library/LegacyPromptFlux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace nuflux{
}

LegacyPromptFlux::LegacyPromptFlux(const std::string& fluxName):
FluxFunction(fluxName),
KneeReweightable("none"){
FluxFunction(fluxName)
{
components[NuMu] =readPromptComponent(detail::getDataPath("LegacyPromptFlux/"+fluxName+"_numupro.dat"));
components[NuMuBar]=readPromptComponent(detail::getDataPath("LegacyPromptFlux/"+fluxName+"_numubarpro.dat"));
components[NuE] =readPromptComponent(detail::getDataPath("LegacyPromptFlux/"+fluxName+"_nuepro.dat"));
Expand Down
4 changes: 0 additions & 4 deletions src/nuflux/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
__all__ = [
"FluxFunction",
"KneeReweightable",
"LegacyConventionalFlux",
"LegacyPromptFlux",
"NuE",
Expand All @@ -10,7 +9,6 @@
"NuTau",
"NuTauBar",
"ParticleType",
"PionKaonAdjustable",
"SplineFlux",
"SplineFlux2",
"availableFluxes",
Expand All @@ -23,7 +21,6 @@

from _nuflux import (
FluxFunction,
KneeReweightable,
LegacyConventionalFlux,
LegacyPromptFlux,
NuE,
Expand All @@ -33,7 +30,6 @@
NuTau,
NuTauBar,
ParticleType,
PionKaonAdjustable,
SplineFlux,
SplineFlux2,
availableFluxes,
Expand Down
21 changes: 7 additions & 14 deletions src/pybindings/module.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,17 @@ register_FluxFunction()
(bp::args("particle_type"), "energy", "cos_zen"))
.add_property("name", &FluxFunction::getName)
.add_property("energy_range",&energy_range)

;

bp::class_<KneeReweightable, boost::shared_ptr<KneeReweightable>, boost::noncopyable>("KneeReweightable", bp::no_init)
.add_property("knee_reweighting_model", &KneeReweightable::getKneeReweightingModel, &KneeReweightable::setKneeReweightingModel)
;

bp::class_<PionKaonAdjustable, boost::shared_ptr<PionKaonAdjustable>, boost::noncopyable>("PionKaonAdjustable", bp::no_init)
.add_property("relative_pion_contribution", &PionKaonAdjustable::getRelativePionContribution, &PionKaonAdjustable::setRelativePionContribution)
.add_property("relative_kaon_contribution", &PionKaonAdjustable::getRelativeKaonContribution, &PionKaonAdjustable::setRelativeKaonContribution)
.add_property("knee_reweighting_model", &FluxFunction::getKneeReweightingModel, &FluxFunction::setKneeReweightingModel)
;

bp::class_< LegacyConventionalFlux, boost::shared_ptr<LegacyConventionalFlux>,
bp::bases<FluxFunction, PionKaonAdjustable, KneeReweightable> >("LegacyConventionalFlux", bp::no_init)
bp::class_<LegacyConventionalFlux, boost::shared_ptr<LegacyConventionalFlux>,
bp::bases<FluxFunction> >("LegacyConventionalFlux", bp::no_init)
.add_property("relative_pion_contribution", &LegacyConventionalFlux::getRelativePionContribution, &LegacyConventionalFlux::setRelativePionContribution)
.add_property("relative_kaon_contribution", &LegacyConventionalFlux::getRelativeKaonContribution, &LegacyConventionalFlux::setRelativeKaonContribution)
;

bp::class_< LegacyPromptFlux, boost::shared_ptr<LegacyPromptFlux>,
bp::bases<FluxFunction, KneeReweightable> >("LegacyPromptFlux", bp::no_init)
bp::class_<LegacyPromptFlux, boost::shared_ptr<LegacyPromptFlux>,
bp::bases<FluxFunction> >("LegacyPromptFlux", bp::no_init)
;

{
Expand Down
1 change: 1 addition & 0 deletions tests/pion_contrib.json

Large diffs are not rendered by default.

Loading
Loading