Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ LOAD_LIBRARY

BE_FUNCTION(set_model_pars, void, (pybind11::dict&), "set_model_pars", "gledeliBE_set_model_pars")
BE_FUNCTION(set_model_names, void, (pybind11::list&), "set_model_names", "gledeliBE_set_model_names")
BE_FUNCTION(set_lnlike_cutoff, void, (double&), "set_lnlike_cutoff", "gledeliBE_set_lnlike_cutoff")
BE_FUNCTION(run, pybind11::dict, (pybind11::dict&), "run", "gledeliBE_run")
BE_FUNCTION(get_results, pybind11::dict, (), "get_results", "gledeliBE_get_results")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ START_MODULE
NLDModelCT_and_discretes, NLDModelBSFG_and_discretes)
BACKEND_REQ(gledeliBE_set_model_pars, (), void, (pybind11::dict&))
BACKEND_REQ(gledeliBE_set_model_names, (), void, (pybind11::list&))
BACKEND_REQ(gledeliBE_set_lnlike_cutoff, (), void, (double&))
BACKEND_REQ(gledeliBE_run, (), pybind11::dict, (pybind11::dict&))
BACKEND_REQ(gledeliBE_get_results, (), pybind11::dict, ())
#undef FUNCTION
Expand Down
17 changes: 12 additions & 5 deletions NuclearBit/src/NuclearBit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@ namespace Gambit
{
using namespace Pipes::getGledeliResults;

// The first time this function is run we let
// gledeli know which GAMBIT models are in use.
// Initialization of gledeli
static bool first = true;
if (first)
{
// Get a set<str> with the names of active GAMBIT models and cast it to a pybind11::list
pybind11::list active_models_list = pybind11::cast(Models::ModelDB().get_activemodels());
// Pass the list to the gledeli backend.
BEreq::gledeliBE_set_model_names(active_models_list);

// Read lnlike_cutoff from the YAML file and pass it to the gledeli backend
double lnlike_cutoff = runOptions->getValue<double>("lnlike_cutoff");
BEreq::gledeliBE_set_lnlike_cutoff(lnlike_cutoff);

first = false;
}

Expand Down Expand Up @@ -86,9 +90,12 @@ namespace Gambit
// Get the result (map<str,double>) from the gledeli backend
pybind11::dict gledeli_results = BEreq::gledeliBE_get_results();

// std::map<std::string,double> gledeli_results& = BEreq::gledeliBE_get_results();
// gledeli_results = BEreq::gledeliBE_get_results();
// result = gledeli_results;
// Did gledeli accept this point?
if( !gledeli_results.contains("valid_point") ) { NuclearBit_error().raise(LOCAL_INFO, "The expected 'valid_point' key is not found in the pybind11:dict 'gledeli_results'"); }
if( !gledeli_results["valid_point"].cast<bool>() )
{
invalid_point().raise("Parameter point invalidated by gledeli.");
}

// Fill the result map (map<str,double>) of this function
for (auto& kv : gledeli_results)
Expand Down
10 changes: 7 additions & 3 deletions yaml_files/NuclearBit_demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ ObsLikes:

Rules:

# None required, since no module dependencies to be resolved.
# Set options for the getGledeliResults function in NuclearBit
- capability: gledeliResults
function: getGledeliResults
options:
lnlike_cutoff: -5e5


Logger:
Expand All @@ -161,6 +165,6 @@ KeyValues:

print_timing_data: false

likelihood:
model_invalid_for_lnlike_below: -5e5
# likelihood:
# model_invalid_for_lnlike_below: -5e5