These are chat archives for bluescarni/pagmo_reborn

22nd
May 2016
Francesco Biscani
@bluescarni
May 22 2016 09:03
ok now the serialization stuff seems to work:
class prob(object):
    def fitness(self,v):
        return [v[0]*v[0]]
    def get_bounds(self):
        return (array([0.]*200),[1]*200)
    def get_nobj(self):
        return 1
    def has_gradient(self):
        return True
    def gradient(self,dv):
        raise
    def get_name(self):
        return 'đậằşđαśdsaad'
In [10]: p  = _core.problem(prob())

In [11]: p
Out[11]: 
Problem name: đậằşđαśdsaad
        Global dimension:                       200
        Fitness dimension:                      1
        Number of objectives:                   1
        Equality constraints dimension:         0
        Inequality constraints dimension:       0
        Lower bounds: [0, 0, 0, 0, 0, ... ]
        Upper bounds: [1, 1, 1, 1, 1, ... ]

        Has gradient: true
        User implemented gradient sparsity: false
        Expected gradients: 200
        Has hessians: false
        User implemented hessians sparsity: false

        Function evaluations: 0
        Gradient evaluations: 0

In [12]: loads(dumps(p))
Out[12]: 
Problem name: đậằşđαśdsaad
        Global dimension:                       200
        Fitness dimension:                      1
        Number of objectives:                   1
        Equality constraints dimension:         0
        Inequality constraints dimension:       0
        Lower bounds: [0, 0, 0, 0, 0, ... ]
        Upper bounds: [1, 1, 1, 1, 1, ... ]

        Has gradient: true
        User implemented gradient sparsity: false
        Expected gradients: 200
        Has hessians: false
        User implemented hessians sparsity: false

        Function evaluations: 0
        Gradient evaluations: 0
note the name in UTF-8 characters
this works in Python 3, I have to port a couple of things in order to make it work with Python 2 as they completely changed the way they handle byte streams between versions
Francesco Biscani
@bluescarni
May 22 2016 09:08
so just for the record, it wasn't straightforward to make it work, but the Boost.Python error messages were what pointed me in the right direction
Francesco Biscani
@bluescarni
May 22 2016 09:14
I am filling up the logic of the methods detection from python now, then I need to expose the concrete C++ problems and finally write tests
@darioizzo if we want to be able to use the concrete problems from Python (e.g., rosenbrock) we need to add extra checking in the fitness function etc.
because if you call the fitness function with a vector of the wrong size, you gonna end up doing out-of-bound accesses
Dario Izzo
@darioizzo
May 22 2016 10:53
@bluescarni FANTASTIC!!!
On the extra check, checking the size of x? I guess is np, I thought I already put it ...
Francesco Biscani
@bluescarni
May 22 2016 10:54
yes.. if you pass a numpy array of size 3 and the fitness function expects 5, boom
gradient as well.. I think those are the only 2 methods which accept input right?
Dario Izzo
@darioizzo
May 22 2016 10:56
but we check_decision_vector before calling fitness no?
and there the size is checked .... no?
Francesco Biscani
@bluescarni
May 22 2016 10:58
not if you call directly the fitness method of the rosenbrock object
I thought we said to expose those as well?
I am off to the agriturismo, will be back in the evening
Dario Izzo
@darioizzo
May 22 2016 11:00
cia'
Dario Izzo
@darioizzo
May 22 2016 11:08
on the extra check -> not ideal, but on the other hand its just a size check. From the user point of view we will document that when writing a C++ problem to expose to python such a check is necessary
    def get_nobj(self):
        return 1
this is by default .... try returning 2 to check all is good
Francesco Biscani
@bluescarni
May 22 2016 16:12
yes I was just doing experiments with the get_nobj()
the checks are not a big deal, it's 1 integral comparison... on the other hand we could as well adopt the policy that on the Python side the exposed C++ problems have only the constructor and the stream operator implemented, so the bare minimum to use them to construct a problem and print to screen just for sanity check
Francesco Biscani
@bluescarni
May 22 2016 16:20
on the matter of exposing user-defined problems: right now (and in pagmo legacy as well I guess?) it's easy if you modify your local copy of pagmo, but I think in the future we should have a plan that external packages can add their own problems/algos in an independent way
I imagine we should have a set ot PyGMO headers to be installed alongside the usual PaGMO ones, so that one can write a Python extension which includes #include <pagmo/pygmo.hpp> and get all the nice functionality for the exposition of the C++ classes
I think something like this should be done if we want to push the affiliated packages idea
Dario Izzo
@darioizzo
May 22 2016 17:39
@bluescarni codecov is back !
@bluescarni agree on the pygmo header ..... one of the first attempts we could make to define an affiliated package is the GTOP database .... its a good example that could allow us to define the "practice"
Francesco Biscani
@bluescarni
May 22 2016 18:47
This message was deleted
@darioizzo what so you mean about codecov? and what do you think, regarding the C++ methods, of exposing only ctors, streaming and problem-specific methods (e.g., get_best())?
Dario Izzo
@darioizzo
May 22 2016 19:53
You mean to avoid a direct call? We can do that too, but adding a check as you said its no biggie
I do not like to have an asymmetry between c++ and python prob
Francesco Biscani
@bluescarni
May 22 2016 19:54
point is that these exposed c++ problems exist only to init a generic problem, so in some sense it would make things conceptually simpler... if you want to actually use the problem, you need to stuff it into a problem object
but I see your point as well... it's just that then we need to make sure the checks are done properly everywhere
Dario Izzo
@darioizzo
May 22 2016 20:58
In "our" cpp problems it would not be difficult .... it's just a check to begin the fitness grad Hess with ....
But for the time being I would go your way of not exposing it
If we find it weird we can add them in the future
Francesco Biscani
@bluescarni
May 22 2016 21:04
keyword args seem to work in boost python as well
Dario Izzo
@darioizzo
May 22 2016 21:16
that is cool ... kwargs is the best pythin feat
Francesco Biscani
@bluescarni
May 22 2016 21:19
.def("fitness",&fitness_wrapper,"Fitness.",(bp::arg("dv"))); simple as that
Dario Izzo
@darioizzo
May 22 2016 21:21
how is the doc string then?
vado a dormire che oggi sono distrutto .... notte :)
Francesco Biscani
@bluescarni
May 22 2016 21:25
In [7]: p.fitness?
Docstring:
fitness( (problem)arg1, (object)dv) -> object :
    Fitness.
Type:      method
like this from ipython
notte!