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
26 changes: 26 additions & 0 deletions src/ugo/Python/UGO.SPC
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BEGIN UGO SPECIFICATIONS
error-printout-device 6
printout-device 6
alive-device 40
print-level 1
start-print -1
stop-print -1
maximum-number-of-iterations 100
block-of-storage-allocated 1000
iterations-between-printing 1
out-of-core-buffer 70
lipschitz-estimate-used 3
next-interval-selection-method 1
refine-with-newton-iterations 5
global-lipschitz-constant -1.0
reliability-parameter 1.2
lipschitz-lower-bound 1.0D-8
max-interval-length-required 1.0D-5
try-newton-tolerence 1.0D-3
sufficient-gradient-tolerence 1.0D-6
sufficient-objective-value -1.0D+32
maximum-cpu-time-limit -1.0
maximum-clock-time-limit -1.0
space-critical no
deallocate-error-fatal no
END UGO SPECIFICATIONS
10 changes: 10 additions & 0 deletions src/ugo/Python/test_ugo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
x_u = 2
ugo.load(x_l,x_u,options=options)

# load data (and optionally non-default specfile)
x_l = -1
x_u = 2
ugo.load(x_l,x_u,specfile='UGO.SPC')

# load data (and optionally non-default options and specfile)
x_l = -1
x_u = 2
ugo.load(x_l,x_u,options=options,specfile='UGO.SPC')

# define objective function
# NB python functions have access to external variables
# So no need for userdata like in C or Fortran
Expand Down
19 changes: 15 additions & 4 deletions src/ugo/Python/ugo_pyiface.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,22 +405,33 @@ static PyObject* py_ugo_initialize(PyObject *self){

static PyObject* py_ugo_load(PyObject *self, PyObject *args, PyObject *keywds){
PyObject *py_options = NULL;
const char *specfile = NULL;
double x_l, x_u;

// Check that package has been initialised
if(!check_init(init_called))
return NULL;

// Parse positional and keyword arguments * Note sentinel at end
static char *kwlist[] = {"x_l","x_u","options", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "dd|O", kwlist,
&x_l, &x_u, &py_options))
static char *kwlist[] = {"x_l","x_u","options", "specfile", NULL};
if(!PyArg_ParseTupleAndKeywords(args, keywds, "dd|Os", kwlist,
&x_l, &x_u, &py_options, &specfile))
return NULL;

// Warn if both options and specfile are passed
if(py_options && specfile)
PyErr_WarnEx(PyExc_RuntimeWarning,
"both options dictionary and specfile passed, for settings specified twice those in options will take precedence."
,1); // raise here

// Reset control options
ugo_reset_control(&control, &data, &status);

// Update UGO control options
// Update UGO control options from specfile
if(specfile)
ugo_read_specfile(&control, specfile);

// Update UGO control options from options dictionary
if(!ugo_update_control(&control, py_options))
return NULL;

Expand Down