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

Layer pybindings #20

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f75205b
enable reading GF and Na from Python
atrettin Aug 26, 2020
63c25c4
small test example for explicit layer calculator
atrettin Aug 27, 2020
0089b64
correct warning message
atrettin Aug 28, 2020
2ac81d2
implement new layer-wise calculator class
atrettin Aug 28, 2020
2ef675a
add example testing evaluation with given state
atrettin Aug 29, 2020
7394d43
marray slices cannot be used directly
atrettin Aug 29, 2020
69b74de
first attempt at Pybindings that at least compiles
atrettin Aug 29, 2020
d9ac2e9
remove verbosity
atrettin Aug 29, 2020
a6d89f6
add missing pybinding to get states
atrettin Aug 29, 2020
dfb6392
use correct projector in constant density mode
atrettin Aug 30, 2020
5a6b6c9
clarify comments
atrettin Aug 31, 2020
494677c
support averaging when evaluating interpolated states
atrettin Sep 1, 2020
1442eed
enable pybinding to distance averaging
atrettin Sep 16, 2020
922bec0
implement low-pass filtering in nuSQuIDS
atrettin Nov 27, 2020
dc825a2
add method to get neutrino type
atrettin Nov 30, 2020
6dfae33
improve pybindings for nusquids layers and prepare enabling of `both`…
atrettin Dec 2, 2020
fb3eca9
enable `both` propagation mode for single energy, improve pybinding
atrettin Dec 3, 2020
1c14b3e
declare array inputs into functions const
atrettin Jan 7, 2021
5c692f7
decrease reference count to converted numpy array to avoid memory leaks
atrettin Jan 7, 2021
c9ab9e8
Merge branch 'pyrefcount' into layer_pybindings
atrettin Jan 7, 2021
a643d32
guard all possible returns from convertible
atrettin Jan 8, 2021
d64e7b2
Merge branch 'pyrefcount' into layer_pybindings
atrettin Jan 8, 2021
8b49d04
better comments
atrettin Jan 12, 2021
8492e35
add override with different low-pass filter settings for each event
atrettin Jan 28, 2021
91ca064
add linear ramp to standard squids averaging
atrettin Aug 9, 2021
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
5 changes: 5 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ OBJECTS = $(patsubst src/%.cpp,build/%.o,$(SOURCES))
EXAMPLES := examples/Single_energy/single_energy \
examples/Multiple_energy/multiple_energy \
examples/Atm_default/atm_default \
examples/explicit_layers/explicit_layers \
examples/Bodies/bodies \
examples/Xsections/xsections \
examples/NSI/nsi \
Expand Down Expand Up @@ -526,6 +527,10 @@ examples/Atm_default/atm_default : $(DYN_PRODUCT) examples/Atm_default/main.cpp
@echo Compiling atmospheric example
@$(CXX) $(EXAMPLES_FLAGS) examples/Atm_default/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@

examples/explicit_layers/explicit_layers : $(DYN_PRODUCT) examples/explicit_layers/main.cpp
@echo Compiling explicit layers example
$(CXX) $(EXAMPLES_FLAGS) examples/explicit_layers/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@

build/exBody.o : examples/Bodies/exBody.h examples/Bodies/exBody.cpp
@$(CXX) $(EXAMPLES_FLAGS) -c examples/Bodies/exBody.cpp -o $@

Expand Down
109 changes: 109 additions & 0 deletions examples/explicit_layers/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include <nuSQuIDS/nuSQuIDS.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <chrono> // for high_resolution_clock

using namespace nusquids;

int main(){

squids::Const units;
// unsigned int evalThreads = 8;
// std::vector<nuSQUIDS> nusq_array;

marray<double,2> lengths {8,10};
marray<double,2> densities {8,10};
marray<double,2> ye {8,10};
marray<double,1> energies {8};
// These lengths and densities are completely made up nonsense.
// The intention is that we would have a pybinding in the real
// world where we pass explicit distances and densities that were
// calculated elsewhere.
for (int i = 0; i < lengths.extent(0); i++){
for (int j = 1; j < lengths.extent(1) + 1; j++){
lengths[i][j-1] = 5000./j * units.km;
densities[i][j-1] = (13. + i)/j;
ye[i][j-1] = 0.5;
}
energies[i] = 10.*units.GeV;
}

std::cout << "Begin: constructing nuSQuIDS-Layers object" << std::endl;
nuSQUIDSLayers<> nus_layer(lengths, densities, ye, energies, 3, neutrino);
std::cout << "End: constructing nuSQuIDS-Layers object" << std::endl;

nus_layer.Set_MixingParametersToDefault();
nus_layer.Set_AllowConstantDensityOscillationOnlyEvolution(false);

marray<double,1> ini_state({3},{0,1,0});
nus_layer.Set_initial_state(ini_state, flavor);

marray<double,2> states;

std::cout << "Initial interaction picture states:" << std::endl;
states = nus_layer.GetStatesArr();
for (int i=0; i<states.extent(0); i++){
for (int j=0; j<states.extent(1); j++)
std::cout << states[i][j] << " ";
std::cout << std::endl;
}

std::cout << "Initial flavor state:" << std::endl;
for (int n = 0; n < lengths.extent(0); n ++){
std::cout << n << ": ";
for(int i = 0; i < 3; i++){
std::cout << nus_layer.EvalFlavorAtNode(i, n) << " ";
}
std::cout << std::endl;
}

nus_layer.Set_EvalThreads(1);

auto start = std::chrono::high_resolution_clock::now();

nus_layer.EvolveState();

auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
std::cout << "evolution time: " << elapsed.count() << " s" << std::endl;

std::cout << "Final interaction picture states:" << std::endl;
states = nus_layer.GetStatesArr();
for (int i=0; i<states.extent(0); i++){
for (int j=0; j<states.extent(1); j++)
std::cout << states[i][j] << " ";
std::cout << std::endl;
}

std::cout << "Final flavor state:" << std::endl;
for (int n = 0; n < lengths.extent(0); n ++){
std::cout << n << ": ";
for(int i = 0; i < 3; i++){
std::cout << nus_layer.EvalFlavorAtNode(i, n) << " ";
}
std::cout << std::endl;
}

// The following demonstrates evaluation with a given interaction picture state.
// We just use the states as they are computed at the nodes, but in real life we
// would do some sort of interpolation externally.
std::cout << "Evaluating with states:" << std::endl;
marray<double,1> summed_lengths = lengths.sum(1);

for (int n = 0; n < lengths.extent(0); n ++){
std::cout << n << ": ";
for(int i = 0; i < 3; i++){
// Is there no way to convert the slice more easily?
marray<double,1> state {states.extent(1)};
for (int j=0; j<state.extent(0); j++)
state[j] = states[n][j];
std::cout << nus_layer.EvalWithState(
i, summed_lengths[n], 10.*units.GeV, state
) << " ";
}
std::cout << std::endl;
}
return 0;
}
Loading