Skip to content

Commit

Permalink
Merge pull request #11 from wlav/python-build-fix
Browse files Browse the repository at this point in the history
Python interface build/run fixes
  • Loading branch information
montplaisir committed Dec 18, 2020
2 parents d985bba + d381684 commit 5e5c565
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions interfaces/PyNomad/nomadCySimpleInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "Math/RNG.hpp"
#include "Nomad/nomad.hpp"
#include "Param/AllParameters.hpp"
#include "Cache/CacheBase.hpp"

#include <Python.h>
#include <signal.h>
Expand Down Expand Up @@ -419,7 +420,7 @@ static int runNomad(Callback cb,

// Set cbL to NULL if blocks are not used.
// Set cb to NULL if blocks are used.
if (allParams->getEvaluatorControlParams()->getAttributeValue<size_t>("BB_MAX_BLOCK_SIZE") > 1)
if (allParams->getEvaluatorControlGlobalParams()->getAttributeValue<size_t>("BB_MAX_BLOCK_SIZE") > 1)
{
// Using blocks
cb = nullptr;
Expand All @@ -441,8 +442,8 @@ static int runNomad(Callback cb,

// Set the best feasible and best infeasible solutions
std::vector<NOMAD::EvalPoint> evalPointFeasList, evalPointInfList;
auto nbFeas = NOMAD::CacheBase::getInstance()->findBestFeas(evalPointFeasList, NOMAD::Point(), NOMAD::EvalType::BB);
auto nbInf = NOMAD::CacheBase::getInstance()->findBestInf(evalPointInfList, NOMAD::INF, NOMAD::Point(), NOMAD::EvalType::BB);
auto nbFeas = NOMAD::CacheBase::getInstance()->findBestFeas(evalPointFeasList, NOMAD::Point(), NOMAD::EvalType::BB, nullptr);
auto nbInf = NOMAD::CacheBase::getInstance()->findBestInf(evalPointInfList, NOMAD::INF, NOMAD::Point(), NOMAD::EvalType::BB, nullptr);

if (nbInf > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion interfaces/PyNomad/runTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def bb(x):

params = ["BB_OUTPUT_TYPE OBJ", "MAX_BB_EVAL 100", "UPPER_BOUND * 1", "DISPLAY_DEGREE 2", "DISPLAY_ALL_EVAL false", "DISPLAY_STATS BBE THREAD_NUM OBJ"]

[ x_return, f_return, h_return, nb_evals, nb_iters, stopflag ] = PyNomad.optimize(bb, x0, lb, ub, params)
x_return, f_return, h_return, nb_evals, nb_iters, stopflag = PyNomad.optimize(bb, x0, lb, ub, params)
print ("\n NOMAD outputs \n X_sol={} \n F_sol={} \n H_sol={} \n NB_evals={} \n NB_iters={} \n".format(x_return,f_return,h_return,nb_evals,nb_iters))
10 changes: 5 additions & 5 deletions interfaces/PyNomad/runTest_BlockEval.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def bb_block(block):
# eval each point
x = block.get_x(k)
dim = x.size()
f = sum([x.get_coord(i)**2 for i in range(dim)])
f = sum([x.get_coord(i)**2 for i in range(dim)])
x.setBBO(str(f).encode("UTF-8"), B"OBJ")
evalOk[k] = True
except:
print("Unexpected error in bb_block()", sys.exc_info()[0])
except Exception as e:
print("Unexpected error in bb_block()", str(e))
return 0
return evalOk # list where 1 is success, 0 is a failed evaluation

Expand All @@ -27,7 +27,7 @@ def bb_block(block):

params = ["BB_OUTPUT_TYPE OBJ", "MAX_BB_EVAL 100", "UPPER_BOUND * 1"]
params += ["DISPLAY_DEGREE 2", "DISPLAY_STATS BBE BLK_SIZE OBJ", "DISPLAY_ALL_EVAL false"]
params += ["NB_THREADS_OPENMP 1", "BB_MAX_BLOCK_SIZE 4"]
params += ["NB_THREADS_OPENMP 1", "BB_MAX_BLOCK_SIZE 4"]

[ x_return, f_return, h_return, nb_evals, nb_iters, stopflag ] = PyNomad.optimize(bb_block, x0, lb, ub, params)
x_return, f_return, h_return, nb_evals, nb_iters, stopflag = PyNomad.optimize(bb_block, x0, lb, ub, params)
print ("\n NOMAD outputs \n X_sol={} \n F_sol={} \n H_sol={} \n NB_evals={} \n NB_iters={} \n".format(x_return,f_return,h_return,nb_evals,nb_iters))
4 changes: 3 additions & 1 deletion interfaces/PyNomad/setup_PyNomad.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@
os.environ["CXX"] = "g++"

setup(
name='PyNomad',

ext_modules = cythonize(Extension(
"PyNomad", # extension name
sources = ["PyNomad.pyx", "nomadCySimpleInterface.cpp"], # Cython source and interface
sources = ["PyNomad.pyx"], # Cython source and interface
include_dirs = os_include_dirs,
extra_compile_args = compile_args,
extra_link_args = link_args,
Expand Down

0 comments on commit 5e5c565

Please sign in to comment.