From ab56074bb1a1f428c5c0c2a1781e00b02bb58f03 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 9 Mar 2019 11:23:30 +0000 Subject: [PATCH 1/2] assert(3) --- C/cdmgr.c | 43 +++++++++++++++++++ C/exec.c | 42 ------------------ C/lu_absmi_insts.h | 2 +- .../ProbLog/problog_examples/learn_graph.pl | 4 +- .../problog_examples/learn_graph_lbdd.pl | 1 + packages/ProbLog/problog_learning.yap | 23 +++++----- 6 files changed, 58 insertions(+), 57 deletions(-) diff --git a/C/cdmgr.c b/C/cdmgr.c index c14a69ab0..c7fd23566 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -74,6 +74,49 @@ static void kill_first_log_iblock(LogUpdIndex *, LogUpdIndex *, PredEntry *); #define PredArity(p) (p->ArityOfPE) #define TRYCODE(G, F, N) ((N) < 5 ? (op_numbers)((int)F + (N)*3) : G) +PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) { + Term t0 = t; + +restart: + if (IsVarTerm(t)) { + Yap_ThrowError(INSTANTIATION_ERROR, t0, pname); + return NULL; + } else if (IsAtomTerm(t)) { + PredEntry *ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); + return ap; + } else if (IsIntegerTerm(t) && tmod == IDB_MODULE) { + return Yap_FindLUIntKey(IntegerOfTerm(t)); + } else if (IsPairTerm(t)) { + t = Yap_MkApplTerm(FunctorCsult, 1, &t); + goto restart; + } else if (IsApplTerm(t)) { + Functor fun = FunctorOfTerm(t); + if (IsExtensionFunctor(fun)) { + Yap_ThrowError(TYPE_ERROR_CALLABLE, t, pname); + return NULL; + } + if (fun == FunctorModule) { + Term tmod = ArgOfTerm(1, t); + if (IsVarTerm(tmod)) { + Yap_ThrowError(INSTANTIATION_ERROR, t0, pname); + return NULL; + } + if (!IsAtomTerm(tmod)) { + Yap_ThrowError(TYPE_ERROR_ATOM, t0, pname); + return NULL; + } + t = ArgOfTerm(2, t); + goto restart; + } + PredEntry *ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod)); + return ap; + } else { + Yap_ThrowError(TYPE_ERROR_CALLABLE, t0, pname); + } + return NULL; +} + + static void InitConsultStack(void) { CACHE_REGS LOCAL_ConsultLow = (consult_obj *)Yap_AllocCodeSpace(sizeof(consult_obj) * diff --git a/C/exec.c b/C/exec.c index 58f9788c4..3d9aae042 100755 --- a/C/exec.c +++ b/C/exec.c @@ -159,48 +159,6 @@ Term Yap_ExecuteCallMetaCall(Term g, Term mod) { return Yap_MkApplTerm(PredMetaCall->FunctorOfPred, 4, ts); } -PredEntry *Yap_get_pred(Term t, Term tmod, const char *pname) { - Term t0 = t; - -restart: - if (IsVarTerm(t)) { - Yap_ThrowError(INSTANTIATION_ERROR, t0, pname); - return NULL; - } else if (IsAtomTerm(t)) { - PredEntry *ap = RepPredProp(Yap_GetPredPropByAtom(AtomOfTerm(t), tmod)); - return ap; - } else if (IsIntegerTerm(t) && tmod == IDB_MODULE) { - return Yap_FindLUIntKey(IntegerOfTerm(t)); - } else if (IsPairTerm(t)) { - t = Yap_MkApplTerm(FunctorCsult, 1, &t); - goto restart; - } else if (IsApplTerm(t)) { - Functor fun = FunctorOfTerm(t); - if (IsExtensionFunctor(fun)) { - Yap_ThrowError(TYPE_ERROR_CALLABLE, t, pname); - return NULL; - } - if (fun == FunctorModule) { - Term tmod = ArgOfTerm(1, t); - if (IsVarTerm(tmod)) { - Yap_Error(INSTANTIATION_ERROR, t0, pname); - return NULL; - } - if (!IsAtomTerm(tmod)) { - Yap_Error(TYPE_ERROR_ATOM, t0, pname); - return NULL; - } - t = ArgOfTerm(2, t); - goto restart; - } - PredEntry *ap = RepPredProp(Yap_GetPredPropByFunc(fun, tmod)); - return ap; - } else { - Yap_Error(TYPE_ERROR_CALLABLE, t0, pname); - } - return NULL; -} - Term Yap_TermToIndicator(Term t, Term mod) { CACHE_REGS diff --git a/C/lu_absmi_insts.h b/C/lu_absmi_insts.h index bc67bebdf..96b25f44b 100644 --- a/C/lu_absmi_insts.h +++ b/C/lu_absmi_insts.h @@ -470,7 +470,7 @@ LogUpdClause *lcl = PREG->y_u.OtILl.d; UInt timestamp = IntegerOfTerm(((CELL *)(B_YREG+1))[ap->ArityOfPE]); - /* fprintf(stderr,"- %p/%p %d %d %p\n",PREG,ap,timestamp,ap->TimeStampOfPred,PREG->y_u.OtILl.d->ClCode);*/ + fprintf(stderr,"- %p/%p %lu/%lu %lu-%lu\n",PREG,ap,timestamp,ap->TimeStampOfPred,PREG->y_u.OtILl.d->ClTimeStart,PREG->y_u.OtILl.d->ClTimeEnd); #if defined(YAPOR) || defined(THREADS) if (PP != ap) { if (PP) UNLOCKPE(16,PP); diff --git a/packages/ProbLog/problog_examples/learn_graph.pl b/packages/ProbLog/problog_examples/learn_graph.pl index 5f29b8062..c8f391a5f 100644 --- a/packages/ProbLog/problog_examples/learn_graph.pl +++ b/packages/ProbLog/problog_examples/learn_graph.pl @@ -32,8 +32,8 @@ path(X,Y,A,R) :- path(Z,Y,[Z|A],R). % using directed edges in both directions -edge(X,Y) :- problog:dir_edge(Y,X). -edge(X,Y) :- problog:dir_edge(X,Y). +edge(X,Y) :- dir_edge(Y,X). +edge(X,Y) :- dir_edge(X,Y). % checking whether node hasn't been visited before absent(_,[]). diff --git a/packages/ProbLog/problog_examples/learn_graph_lbdd.pl b/packages/ProbLog/problog_examples/learn_graph_lbdd.pl index 19b9b5373..1e30c9285 100644 --- a/packages/ProbLog/problog_examples/learn_graph_lbdd.pl +++ b/packages/ProbLog/problog_examples/learn_graph_lbdd.pl @@ -98,3 +98,4 @@ test_example(33,path(5,4),0.57). test_example(34,path(6,4),0.51). test_example(35,path(6,5),0.69). +:- set_problog_flag(init_method,([Query,X,Y],N,Bdd,graph2bdd(X,Y,N,Bdd))). diff --git a/packages/ProbLog/problog_learning.yap b/packages/ProbLog/problog_learning.yap index 857f3580c..019463a57 100644 --- a/packages/ProbLog/problog_learning.yap +++ b/packages/ProbLog/problog_learning.yap @@ -363,7 +363,7 @@ reset_learning :- retractall(current_iteration(_)), retractall(example_count(_)), retractall(query_probability_intern(_,_)), - retractall(query_gradient_intern(_,_,_)), + retractall(query_gradient_intern(_,_,_,_)), retractall(last_mse(_)), retractall(query_is_similar(_,_)), retractall(query_md5(_,_,_)), @@ -392,7 +392,7 @@ do_learning(Iterations,Epsilon) :- Iterations>0, do_learning_intern(Iterations,Epsilon). do_learning(_,_) :- - format(user_error,'~n~Error: No training examples specified.~n~n',[]). + format(user_error,'~n~Error: Not raining examples specified.~n~n',[]). do_learning_intern(0,_) :- @@ -430,6 +430,7 @@ do_learning_intern(Iterations,Epsilon) :- ( retractall(last_mse(_)), logger_get_variable(mse_trainingset,Current_MSE), + writeln(Current_MSE:Last_MSE), assertz(last_mse(Current_MSE)), !, MSE_Diff is abs(Last_MSE-Current_MSE) @@ -444,7 +445,6 @@ do_learning_intern(Iterations,Epsilon) :- (problog_flag(rebuild_bdds,BDDFreq),BDDFreq>0,0 =:= CurrentIteration mod BDDFreq) -> ( - retractall(values_correct), retractall(query_is_similar(_,_)), retractall(query_md5(_,_,_)), empty_bdd_directory, @@ -627,12 +627,13 @@ init_one_query(QueryID,Query,Type) :- % check wether this BDD is similar to another BDD %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ( - problog_flag(check_duplicate_bdds,true) +listing(query_md5), + problog_flag(check_duplicate_bdds,true) -> ( - calc_md5(Filename,Query_MD5), + calc_md5(Filename,Query_MD5), ( - query_md5(OtherQueryID,Query_MD5,Type) + query_md5(OtherQueryID,Query_MD5,Type) -> ( assertz(query_is_similar(QueryID,OtherQueryID)), @@ -682,7 +683,7 @@ update_values :- problog:dynamic_probability_fact_extract(Term, Prob2), inv_sigmoid(Prob2,Value), format(Handle, '@x~q_~q~n~10f~n', [ID,GID, Value]))) - ; non_ground_fact(ID) -> + ; non_ground_fact(ID) -> inv_sigmoid(Prob,Value), format(Handle,'@x~q_*~n~10f~n',[ID,Value]) ; @@ -699,7 +700,6 @@ update_values :- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % stop write current probabilities to file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - assertz(values_correct). @@ -710,7 +710,7 @@ update_values :- %= %======================================================================== -update_query_cleanup(QueryID) :- + listing( ( (query_is_similar(QueryID,_) ; query_is_similar(_,QueryID)) -> @@ -734,7 +734,7 @@ update_query(QueryID,Symbol,What_To_Update) :- ( problog_flag(sigmoid_slope,Slope), ((What_To_Update=all;query_is_similar(_,QueryID)) -> Method='g' ; Method='l'), - convert_filename_to_problog_path('simplecudd', Simplecudd), + convert_filename_to_problog_path('simplecudd', Simplecudd), atomic_concat([Simplecudd, ' -i "', Probabilities_File, '"', ' -l "', Query_Directory,'/query_',QueryID, '"', @@ -744,7 +744,6 @@ update_query(QueryID,Symbol,What_To_Update) :- ' > "', Output_Directory, 'values.pl"'],Command), - shell(Command,Error), %shell('cat /home/vsc/Yap/bins/devel/outputvalues.pl',_), @@ -816,7 +815,7 @@ my_load_intern(query_gradient(QueryID,XFactID,Type,Value),Handle,QueryID) :- !, atomic_concat(x,FactID,XFactID), % atom_number(StringFactID,FactID), - assertz(query_gradient_intern(QueryID,FactID,Type,Value)), + assertz(query_gradient_intern(QueryID,XFactID,Type,Value)), read(Handle,X), my_load_intern(X,Handle,QueryID). my_load_intern(X,Handle,QueryID) :- From 4d2b18908deebe89ea9689aa5ae4ae5d545b4496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 11 Mar 2019 19:05:39 +0000 Subject: [PATCH 2/2] fixes --- C/cdmgr.c | 8 ++++---- CMakeLists.txt | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/C/cdmgr.c b/C/cdmgr.c index d7cefa454..3d578ddb4 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1461,7 +1461,7 @@ static int not_was_reconsulted(PredEntry *p, Term t, int mode) { // p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1); } LOCAL_LastAssertedPred = p; - return TRUE; /* careful */ + ret>urn TRUE; /* careful */ } static yamop *addcl_permission_error(const char *file, const char *function, @@ -1748,7 +1748,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref) PELOCK(20, p); /* we are redefining a prolog module predicate */ if (Yap_constPred(p)) { - addcl_permission_error(__FILE__, __FUNCTION__, __LINE__, p, + addcl_permission_error(__FILE__, __FUNCTION__, __LINE__, tf, FALSE); UNLOCKPE(30, p); return false; @@ -2185,7 +2185,7 @@ static Int p_purge_clauses(USES_REGS1) { /* '$purge_clauses'(+Func) */ PELOCK(21, pred); if (pred->PredFlags & StandardPredFlag) { UNLOCKPE(33, pred); - Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, Yap_PredicateIndicator(CurrentModule, pred), "assert/1"); + Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, Yap_PredicateIndicator(CurrentModule, t), "assert/1"); return (FALSE); } purge_clauses(pred); @@ -4102,7 +4102,7 @@ static Int | TabledPredFlag #endif /* TABLING */ )) { - Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, Yap_PredicateIndicator(CurrentModule, ap), + Yap_Error(PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE, Yap_PredicateIndicator(CurrentModule, t), "dbload_get_space/4"); return FALSE; } diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b6e814d6..d96b4c0d0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,6 +384,10 @@ if (GMP_INCLUDE_DIRS) # READLINE_readline_LIBRARY, where to find the READLINE library. # READLINE_ncurses_LIBRARY, where to find the ncurses library [might not be defined] +if (ANDROID) + option (WITH_READLINE "use Readline" OFF) + else() + include(FindReadline) option (WITH_READLINE "use Readline" ON) @@ -392,13 +396,14 @@ if (GMP_INCLUDE_DIRS) # # ADD_SUBDIRECTORY(console/terminal) - if (READLINE_FOUND) + if (READLINE_FOUND AND READLINE_INCLUDE_DIR) List(APPEND YAP_SYSTEM_OPTIONS readline) # required for configure include_directories( ${READLINE_INCLUDE_DIR} ${READLINE_INCLUDE_DIR}/readline ) endif () +endif() include_directories( ${CMAKE_SOURCE_DIR}/H