celinehocquette / magicpopper Goto Github PK
View Code? Open in Web Editor NEWC. Hocquette and A. Cropper, Learning programs with magic values.
Home Page: https://link.springer.com/article/10.1007/s10994-022-06274-w
C. Hocquette and A. Cropper, Learning programs with magic values.
Home Page: https://link.springer.com/article/10.1007/s10994-022-06274-w
When running any of the examples, e.g.
$ python3 popper examples/iggp-magiccoins
the following error is thrown:
Traceback (most recent call last):
File "popper.py", line 7, in <module>
settings = Settings()
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/util.py", line 364, in __init__
elif args.info:
AttributeError: 'Namespace' object has no attribute 'info'
After commenting these lines
--- a/magicpopper/popper/util.py
+++ b/magicpopper/popper/util.py
@@ -361,9 +361,9 @@ class Settings:
elif args.debug:
log_level = logging.DEBUG
logging.basicConfig(format='%(asctime)s %(message)s', level=log_level, datefmt='%H:%M:%S')
- elif args.info:
- log_level = logging.INFO
- logging.basicConfig(format='%(asctime)s %(message)s', level=log_level, datefmt='%H:%M:%S')
+ # elif args.info:
+ # log_level = logging.INFO
+ # logging.basicConfig(format='%(asctime)s %(message)s', level=log_level, datefmt='%H:%M:%S')
self.stats = Stats(info=info, debug=args.debug, stats_file=args.stats_file)
self.stats.logger = self.logger
then he specific MagicPopper examples work, e,g,
python3 popper.py examples/iggp-magiccoins-goal
NO MORE SOLUTIONS
********** SOLUTION **********
Precision:1.00 Recall:1.00 TP:62 FN:0 TN:62 FP:0 Size:5
goal(A,you,100):- my_true_step(A,5).
goal(A,you,0):- my_true_step(A,E),different(5,E).
******************************
Note: running any "plain" Popper examples yields an error:
AttributeError: 'Settings' object has no attribute 'max_vars'
I report a separate issue about this.
When running a Magic example the line "NO MORE SOLUTIONS" is printed before the solutions which is a little confusing.
E.g.:
python3 popper.py examples/iggp-magic-minimal-decay
NO MORE SOLUTIONS
********** SOLUTION **********
Precision:1.00 Recall:1.00 TP:8 FN:0 TN:46 FP:0 Size:6
next_value(A,5):- does(A,player,pressButton).
next_value(A,B):- does(A,player,noop),true_value(A,D),my_succ(B,D).
******************************
(Thanks for MagicPopper! I really like it and will play with some of my own examples. )
Here is a suggestion for the magicpopper examples directory.
It would be great if there was at least one (working) example from each of the problems in ilp-experments.
That would makes them more accessible and also show more of the power of MagicPopper.
Running the interval example give the following solution:
python3 popper.py examples/interval
NO MORE SOLUTIONS
********** SOLUTION **********
Precision:1.00 Recall:1.00 TP:26 FN:0 TN:22 FP:0 Size:26
interval(-36).
interval(-11).
interval(19).
interval(23).
interval(13).
interval(-20).
interval(-15).
interval(-19).
interval(-27).
interval(4).
interval(-29).
interval(-1).
interval(-28).
interval(-9).
interval(-34).
interval(-30).
interval(-8).
interval(-14).
interval(7).
interval(-35).
interval(2).
interval(5).
interval(-16).
interval(12).
interval(-21).
interval(9).
******************************
which is just a listing of the positive instances.
Is this the correct solution? bk.pl and bias.pl include a lot of predicates which seems to indicate that the solutions should use some of these predicates.
I installed Popper un Ubuntu 22.04.2 with Python 3.11.2 and run an example from https://github.com/logic-and-learning-lab/Popper/#library-usage with no problems. Afterwards, I installed magicpopper from https://github.com/celinehocquette/magicpopper/tree/main/magicpopper using pip install .
. The installation overwrites popper-ilp-2.0.0
and the example no longer works. This is the error message:
(.venv) paul@desktop:~/st-python/prolog$ /usr/bin/env /home/paul/st-python/prolog/.venv/bin/python /home/paul/.vscode/extensions/ms-python.python-2023.4.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher 36639 -- /home/paul/st-python/prolog/popper-0.py
Traceback (most recent call last):
File "/home/paul/st-python/prolog/popper-0.py", line 4, in <module>
settings = Settings(kbpath='kinship')
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/paul/st-python/prolog/.venv/lib/python3.11/site-packages/popper/util.py", line 393, in __init__
with open(self.bias_file) as f:
^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: ''
Can these two, Popper and magicpopper, be installed together? Does it even make sense? I'm just learning about ILP, so these questions may be completely clueless.
Hello,
Thank you for making such nice work, which I think will benefit my research a lot. When playing with the software, I found something strange. I am running a toy problem of identifying root causes.
Here is my bk.pl
type_of(u1, ut1).
type_of(u2, ut1).
type_of(u3, ut2).
at_state(amf, ns1).
at_state(smf, ns1).
at_state(nrf, ns1).
at_state(ausf, ns2).
at_state(bsf, ns2).
has_user(c1, u1).
has_user(c2, u1).
has_user(c3, u2).
has_user(c4, u3).
has_user(c5, u3).
has_user(c6, u3).
calls_nf(c1, amf).
calls_nf(c2, amf).
calls_nf(c3, nrf).
calls_nf(c4, ausf).
calls_nf(c5, ausf).
calls_nf(c6, bsf).
and my exs.pl
pos(rootcause(c1, r1)).
pos(rootcause(c2, r1)).
pos(rootcause(c3, r1)).
pos(rootcause(c4, r2)).
pos(rootcause(c5, r2)).
pos(rootcause(c6, r2)).
If I impose such bias
head_pred(rootcause,2).
magic_value(rootcause, 1).
body_pred(has_user, 2).
body_pred(type_of, 2).
magic_value(type_of, 1).
It can successfully find the rules
$python ./magicpopper/popper.py ./magicpopper/examples/rca
********** SOLUTION **********
Precision:1.00 Recall:1.00 TP:6 FN:0 TN:0 FP:0 Size:6
rootcause(A,r1):- has_user(A,D),type_of(D,ut1).
rootcause(A,r2):- type_of(D,ut2),has_user(A,D).
******************************
Or if I use another set of bias
head_pred(rootcause,2).
magic_value(rootcause, 1).
body_pred(calls_nf, 2).
body_pred(at_state, 2).
magic_value(at_state, 1).
It can also successfully find the rules
$python ./magicpopper/popper.py ./magicpopper/examples/rca
********** SOLUTION **********
Precision:1.00 Recall:1.00 TP:6 FN:0 TN:0 FP:0 Size:6
rootcause(A,r1):- calls_nf(A,C),at_state(C,ns1).
rootcause(A,r2):- at_state(C,ns2),calls_nf(A,C).
******************************
However, when I put the 2 sets of bias together, hoping that it can induce both set of rules
head_pred(rootcause,2).
magic_value(rootcause, 1).
body_pred(has_user, 2).
body_pred(type_of, 2).
magic_value(type_of, 1).
body_pred(calls_nf, 2).
body_pred(at_state, 2).
magic_value(at_state, 1).
:-
body_literal(Rule1,Q,_,_),
body_literal(Rule2,Q,_,_),
Rule1 != Rule2.
The program runs forever. Does any one know what was going wrong?
OS: ubuntu 20.04
Python: 3.9.7
Prolog: SWI-Prolog (threaded, 64 bits, version 8.5.15-97-g5c7d1f835)
Any comments will be appreciated.
Next test is to run (MagicPopper's) ilp-experiments. Unfortunately throws an error:
$ cd magicpopper/ilp-experiments
$ python3 ilpexp.py FAST_TEST
Traceback (most recent call last):
File "ilpexp.py", line 3, in <module>
import ilpexp.experiment as experiment
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/experiment.py", line 2, in <module>
from .problem import ALL_PROBLEMS, DEFAULT_PROBLEMS, DEFAULT_LIST_PROBLEMS, MINIMAL_DECAY
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/problem/__init__.py", line 2, in <module>
from .trains import DEFAULT_TRAINS_PROBLEMS, ALL_TRAINS_PROBLEMS
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/problem/trains/__init__.py", line 1, in <module>
from .trains import TrainsProblem
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/problem/trains/trains.py", line 6, in <module>
from ...system import *
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/system/__init__.py", line 2, in <module>
from .popper import BASIC_POPPER, MAGIC_POPPER, Popper, PopperTrainSettings
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/system/popper/__init__.py", line 1, in <module>
from .popper import Popper, PopperTrainSettings, BASIC_POPPER, MAGIC_POPPER, generate_bias_file, generate_bk_file
ImportError: cannot import name 'MAGIC_POPPER' from 'ilpexp.system.popper.popper' (/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/ilp-experiments/ilpexp/system/popper/popper.py)
Both Python version 3.7 and 3.9 give the same error.
Note that this is not the same error that I get when running the "other" (real?) ilp-experiment reported in logic-and-learning-lab/ilp-experiments#18
After fixing the error reporting in #1 (commenting the lines regarding args.info in utils.py), the MagicPopper specific examples works, but for the plain Popper examples errors are thrown.
$ python3 popper.py examples/alleven
Traceback (most recent call last):
File "popper.py", line 7, in <module>
settings = Settings()
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/util.py", line 447, in __init__
self.logger.debug(f'Max vars: {self.max_vars}')
AttributeError: 'Settings' object has no attribute 'max_vars'
After commenting the offending line and the next line (since it yields a similar error):
# self.logger.debug(f'Max vars: {self.max_vars}')
# self.logger.debug(f'Max body: {self.max_body}')
then the program throws this error:
Traceback (most recent call last):
File "popper.py", line 8, in <module>
prog, score, stats = learn_solution(settings)
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/loop.py", line 316, in learn_solution
timeout(settings, popper, (settings,), timeout_duration=int(settings.timeout),)
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/util.py", line 78, in timeout
raise moo
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/util.py", line 70, in timeout
result = func(*args, **kwargs)
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/loop.py", line 67, in popper
generator = Generator(settings, grounder)
File "/home/hakank/inductive_programming/andrewcropper/popper/magicpopper/magicpopper/popper/generate.py", line 40, in __init__
encoding.append(f'max_body({settings.max_body}).')
AttributeError: 'Settings' object has no attribute 'max_body'
Now ilp-experiments almost works. The only issue is the line
python_cmd = os.path.join(sys.exec_prefix, "bin", "python")
in the file ilp-experiments/ilpexp/system/popper/popper.py. It assumes that my Python executable is "/usr/local/bin/python", which not correct since it's "/usr/local/bin/python3".
The following fix seems to work, i.e. using sys.executable instead:
--- a/ilp-experiments/ilpexp/system/popper/popper.py
+++ b/ilp-experiments/ilpexp/system/popper/popper.py
@@ -72,7 +72,7 @@ class Popper(System):
import sys
# could break if the environment contains packages that have custom activation code
# https://stackoverflow.com/questions/51819719/using-subprocess-in-anaconda-environment
- python_cmd = os.path.join(sys.exec_prefix, "bin", "python")
+ python_cmd = sys.executable
python_file = os.sep.join([self.install_dir, 'popper.py'])
run_command([python_cmd, python_file], final_settings, timeout=self.timeout + 10)
At least it work on my machine both when running "plain" Pythons 3.7 as well as running Anaconda's Python 3.9.
The magicpopper repo is currently very large: about 9Gn, of which magicpopper is just a few Mb; the rest is for ilp-experiments (including the .git directories).
Would it be possible to separate these two directories so one can clone just the magicpopper directory?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.