Skip to content

Commit

Permalink
MeTTa --compile=full examples/baseline_compat/hyperon-mettalog_sanity…
Browse files Browse the repository at this point in the history
…/fibo_hang.metta runs !(fibo 80) in 2.24 milliseconds
  • Loading branch information
TeamSPoon committed Feb 8, 2024
1 parent 9a71691 commit 1400d60
Show file tree
Hide file tree
Showing 14 changed files with 603 additions and 282 deletions.
7 changes: 4 additions & 3 deletions MeTTa
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ if [[ $should_compile -eq 1 ]]; then
#else
rm -f $reference_file
if [[ "$never_compile" -eq 0 ]]; then
DEBUG "Compiling $reference_file"
# swipl -l metta_vspace/$PYSWIP_VERSION/metta_interp.pl -g qcompile_mettalog -- --exeout=$reference_file
:
#DEBUG "Compiling $reference_file"
#swipl -l metta_vspace/$PYSWIP_VERSION/metta_interp.pl -g qcompile_mettalog -- --exeout=$reference_file
fi
fi

Expand All @@ -484,7 +485,7 @@ if [[ -z "$reference_file" ]]; then
fi

if [[ -f "$reference_file" ]]; then
rm -f $reference_file
: # rm -f $reference_file
fi

if [[ -f "$reference_file" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Doing: timeout --foreground --kill-after=5 --signal=SIGINT 61 time metta /opt/lo
[()]
[()]
[()]
0.09user 0.00system 0:00.10elapsed 99%CPU (0avgtext+0avgdata 33140maxresident)k
0inputs+0outputs (0major+3619minor)pagefaults 0swaps
0.10user 0.02system 0:00.14elapsed 83%CPU (0avgtext+0avgdata 33204maxresident)k
27928inputs+0outputs (185major+3553minor)pagefaults 0swaps
29 changes: 29 additions & 0 deletions examples/baseline_compat/hyperon-mettalog_sanity/fibo_hang.metta
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

(= (fib $n)
(if (== $n 0)
0
(if (== $n 1)
1
(+ (fib (- $n 1)) (fib (- $n 2))))))

(= (fib1 $a $b $n $i)
(if (< $n 3)
(fib $n)
(if (== $i (- $n 2))
(+ $a $b)
(fib1 $b (+ $a $b) $n (+ $i 1)))))


!(println! (fib 12))

!(fib1 0 1 100 0)

!(println! (fib1 0 1 80 0))

!(fib 80)


!(println! (fib 20))



24 changes: 23 additions & 1 deletion examples/performance/gpt2-like/language_models/pllm_drs.pl
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@

% eval_80/6: Evaluates a Python function call within MeTTa.
% Parameters:
% - Eq: denotes get-type, match, or interpret call.
% - RetType: Expected return type of the MeTTa function.
% - Depth: Recursion depth or complexity control.
% - Self: Context or environment for the evaluation.
% - [MyFun|More]: List with MeTTa function and additional arguments.
% - RetVal: Variable to store the result of the Python function call.
eval_80(Eq, RetType, Depth, Self, [MyFun|More], RetVal) :-
% MyFun as a registered Python function with its module and function name.
metta_atom(Self, ['registered-python-function', PyModule, PyFun, MyFun]),
% Tries to fetch the type definition for MyFun, ignoring failures.
(( get_operator_typedef(Self, MyFun, Params, RetType),
try_adjust_arg_types(RetType, Depth, Self, [RetType|Params], [RetVal|More], [MVal|Adjusted])
)->true; (maplist(as_prolog, More , Adjusted), MVal=RetVal)),
% Constructs a compound term for the Python function call with adjusted arguments.
compound_name_arguments(Call, PyFun, Adjusted),
% Optionally prints a debug tree of the Python call if tracing is enabled.
if_trace(host;python, print_tree(py_call(PyModule:Call, RetVal))),
% Executes the Python function call and captures the result in MVal which propagates to RetVal.
py_call(PyModule:Call, MVal),
% Checks the return value against the expected type and criteria.
check_returnval(Eq, RetType, RetVal).

19 changes: 12 additions & 7 deletions examples/performance/understanding_performance/naive-fib.metta
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
;; Takes Rust MeTTa 10.166 seconds
;; Takes HVM Regular 0.0009 seconds
;; Takes Rust Regular 0.0009 seconds
;; Takes MeTTaLog Regular 15.017 seconds
;; Takes MeTTaLog Tableing 0.017 seconds
;; Takes HVM Regular 0.0009 seconds ;; Guessed
;; Takes Rust Regular 0.0009 seconds ;; Guessed
;; Takes Rust MeTTa 10.166 seconds ;; Tested
;; Takes MeTTaLog Regular 90.6667 seconds ;; Tested
;; Takes MeTTaLog Compiled-Tabling 0.017 seconds ;; Tested
;; Takes MeTTaLog Compiled 2.017 seconds ;; Guessed

;;; !(pragma! tabling true)
;; MeTTaLog only:
;!(pragma! tabling true)
;; MeTTaLog only:
;!(pragma! compiler full)

(=
(fib $n)
Expand All @@ -18,9 +22,10 @@
(fib
(- $n 2))))))

!(fib 10)

!(fib 20)

!(fib 50)
!(fib 80)


Loading

0 comments on commit 1400d60

Please sign in to comment.