ec icon indicating copy to clipboard operation
ec copied to clipboard

Demo example with python solver not working

Open falaktheoptimist opened this issue 4 years ago • 3 comments

I've been trying the demo script given in this section that works fine with the ocaml solver. This works perfectly and is able to solve the tasks

python bin/incr.py 
Failure to load pregex. This is only acceptable if using pypy
Failure to load pregex. This is only acceptable if using pypy
DEPRECATION NOTICE: this module (dreamcoder.ec) will be deleted soon, please update your code to import from dreamcoder.dreamcoder instead
CUDA is available?: False
using cuda?: False
Warning: Recognition model needs feature extractor. Ignoring recognition model.
Running EC on grok-animate @ 2021-04-28 05:34:10.237338 with 8 CPUs and parameters:
         noConsolidation  =  False
         iterations  =  10
         enumerationTimeout  =  10
         useRecognitionModel  =  False
         topk_use_only_likelihood  =  False
         pseudoCounts  =  30.0
         aic  =  1.0
         structurePenalty  =  1.0
         arity  =  3
         taskReranker  =  default
         storeTaskMetrics  =  True
         rewriteTaskMetrics  =  False
         maximumFrontier  =  10
         solver  =  ocaml
         topK  =  2
         evaluationTimeout  =  1.0
         cuda  =  False

Currently using this much memory: 202817536
Currently using this much memory: 202817536
Using a waking task batch of size: 3
Disabling parallelism on the Python side because we only have one job.
If you are using ocaml, there could still be parallelism.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 0.000000 <= MDL < 1.500000. Timeout 10.000000.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 0. |finished| = 1.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 1.500000 <= MDL < 3.000000. Timeout 9.705448.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 0. |finished| = 2.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 3.000000 <= MDL < 4.500000. Timeout 9.429657.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 0. |finished| = 12.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 4.500000 <= MDL < 6.000000. Timeout 9.119417.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 0. |finished| = 16.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 6.000000 <= MDL < 7.500000. Timeout 8.869352.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 0. |finished| = 32.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 7.500000 <= MDL < 9.000000. Timeout 8.613590.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 16.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 9.000000 <= MDL < 10.500000. Timeout 8.307677.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 10.500000 <= MDL < 12.000000. Timeout 8.014529.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 12.000000 <= MDL < 13.500000. Timeout 7.743182.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 13.500000 <= MDL < 15.000000. Timeout 7.429715.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 15.000000 <= MDL < 16.500000. Timeout 7.124215.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 16.500000 <= MDL < 18.000000. Timeout 6.732337.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 18.000000 <= MDL < 19.500000. Timeout 6.307096.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 19.500000 <= MDL < 21.000000. Timeout 5.796163.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 21.000000 <= MDL < 22.500000. Timeout 4.227132.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 22.500000 <= MDL < 24.000000. Timeout 2.094563.
        (ocaml: 8 CPUs. shatter: 80. |fringe| = 80. |finished| = 0.)
We enumerated this many programs, for each task:
         [1824168, 1824168, 1824168]
Generative model enumeration results:
HIT add1 w/ (lambda (incr $0)) ; log prior = -2.197225 ; log likelihood = 0.000000
HIT add2 w/ (lambda (incr2 $0)) ; log prior = -2.197225 ; log likelihood = 0.000000
HIT add3 w/ (lambda (incr (incr2 $0))) ; log prior = -3.295837 ; log likelihood = 0.000000
Hits 3/3 tasks
Average description length of a program solving a task: 2.563429 nats
Generative model average:  0 sec.       median: 0       max: 1  standard deviation 0
Currently using this much memory: 214368256
Frontiers discovered top down: 3
Total frontiers: 3
Currently using this much memory: 214368256
Showing the top 5 programs in each frontier being sent to the compressor:
add1
0.00    (lambda (incr $0))

add2
-0.29   (lambda (incr2 $0))
-1.39   (lambda (incr (incr $0)))

add3
-0.85   (lambda (incr (incr2 $0)))
-0.85   (lambda (incr2 (incr $0)))
-1.95   (lambda (incr (incr (incr $0)))) 

But the same script with python solver fails. (No change in script, just the solver is python one) Is the support for python solver limited?

python bin/incr.py --solver python
Failure to load pregex. This is only acceptable if using pypy
Failure to load pregex. This is only acceptable if using pypy
DEPRECATION NOTICE: this module (dreamcoder.ec) will be deleted soon, please update your code to import from dreamcoder.dreamcoder instead
CUDA is available?: False
using cuda?: False
Warning: Recognition model needs feature extractor. Ignoring recognition model.
Running EC on grok-animate @ 2021-04-28 05:27:37.193696 with 8 CPUs and parameters:
         noConsolidation  =  False
         iterations  =  10
         enumerationTimeout  =  10
         useRecognitionModel  =  False
         topk_use_only_likelihood  =  False
         pseudoCounts  =  30.0
         aic  =  1.0
         structurePenalty  =  1.0
         arity  =  3
         taskReranker  =  default
         storeTaskMetrics  =  True
         rewriteTaskMetrics  =  False
         maximumFrontier  =  10
         solver  =  python
         topK  =  2
         evaluationTimeout  =  1.0
         cuda  =  False

Currently using this much memory: 203104256
Currently using this much memory: 203104256
Using a waking task batch of size: 3
Disabling parallelism on the Python side because we only have one job.
If you are using ocaml, there could still be parallelism.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 0.000000 <= MDL < 1.500000. Timeout 10.000000.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 1.500000 <= MDL < 3.000000. Timeout 9.840024.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 3.000000 <= MDL < 4.500000. Timeout 9.683462.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 4.500000 <= MDL < 6.000000. Timeout 9.505921.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 6.000000 <= MDL < 7.500000. Timeout 9.346369.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 7.500000 <= MDL < 9.000000. Timeout 9.182197.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 9.000000 <= MDL < 10.500000. Timeout 8.985159.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 10.500000 <= MDL < 12.000000. Timeout 8.759223.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 12.000000 <= MDL < 13.500000. Timeout 8.463651.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 13.500000 <= MDL < 15.000000. Timeout 7.592893.
(python) Launching int -> int (3 tasks) w/ 8 CPUs. 15.000000 <= MDL < 16.500000. Timeout 6.155116.
We enumerated this many programs, for each task:
         [31972, 31972, 31972]
Generative model enumeration results:
MISS add1
MISS add2
MISS add3
Hits 0/3 tasks
Average description length of a program solving a task: 0.000000 nats
Generative model no successful times to report statistics on!
Currently using this much memory: 214769664
Frontiers discovered top down: 0
Total frontiers: 0
Currently using this much memory: 214769664
Showing the top 5 programs in each frontier being sent to the compressor:
No compression frontiers; not inducing a grammar this iteration.
Grammar after iteration 3:
0.000000        t0      $_
0.000000        int -> int      incr
0.000000        int -> int      incr2
Currently using this much memory: 214990848

Am using the singularity container for all my work.

falaktheoptimist avatar Apr 28 '21 05:04 falaktheoptimist

Huh, you're right, I'm getting exactly the same problem. Not sure what the deal is. :/

Angular-Angel avatar May 18 '21 17:05 Angular-Angel

I am also interested in the differences between the ocaml and python solver

rkjones4 avatar Aug 12 '21 19:08 rkjones4

I don't know if this is still relevant for someone but I think I found the problem with the python solver.

So I also did some debugging why the python solver is not working for the demo example and actually it was only a false definition of the python primitives. The OCaml primitives are correct and therefore it could solve the problem. If you change the python primitives from:

def _incr(x): return lambda x: x + 1
def _incr2(x): return lambda x: x + 2

to:

def _incr(x): return x + 1
def _incr2(x): return x + 2

it will work. When a lambda function is returned, it waits for a second parameter, but we only need one parameter for this primitive. After changing this, the example works with the Python and pypy solver.

ManuelEberhardinger avatar Oct 05 '22 09:10 ManuelEberhardinger