Commit c83cf076 authored by SOLIMAN Sylvain's avatar SOLIMAN Sylvain

cleanup wgpac code

parent 63e04d0f
......@@ -30,10 +30,7 @@ all: biocham biocham_debug test doc jupyter
quick: unit_tests
.PHONY: all slow test unit_tests doc clean \
modules/graphviz/graphviz_swiprolog.o \
modules/sbml/sbml_swiprolog.o \
modules/partialfrac/roots.o
.PHONY: all slow test unit_tests doc clean
biocham: platform/current $(SWIPL) $(MODULES) toc.org Makefile
$(SWIPL) -q -o biocham \
......
......@@ -181,7 +181,7 @@ compile_from_pivp(PIVP, Input, Output) :-
pivp_compile(PIVP, Input, Output):-
clear_model,
fast(Fast),
get_option(fast_rate, Fast),
set_parameter(fast, Fast),
(
Input = time
......
option(
fast_rate: 1000,
time: 20,
show: {},
method: bsimp,
......
......@@ -9,10 +9,7 @@
op(600, xfy, ::),
op(550, fy, integral),
% Commands
compile_wgpac/1,
fast_reaction_rate/1,
% API
fast/1
compile_wgpac/1
]).
:- doc('Biocham can compile a GPAC circuit (Shannon\'s General Purpose Analog Computer) into a reaction system. Only weak GPACs, in which the integration gate is with respect to time and not a variable, are considered. The variables associated to the different points of the circuits can be named with the "::" operator. Dy default they are named x0, x1,... The syntax of weak GPAC circuits is as follows:').
......@@ -102,54 +99,37 @@ get_fresh(N) :-
assert(fresh_index(M)).
compile_wgpac(Wgpac) :-
compile_wgpac(WgpacSet) :-
biocham_command,
doc('compiles a weak GPAC circuit into a reaction system.'),
type(Wgpac, wgpac),
!,
type(WgpacSet, {wgpac}),
doc('compiles a set of weak GPAC circuits into a reaction system.'),
retractall(fresh_index(_)),
assert(fresh_index(0)),
fast(Rate),
option(fast_rate, arithmetic_expression, Rate, '
This reaction constant (defaulting to 1000) is used in the reactions for
computing the results of the sum and product GPAC blocks, and in the
annihilation reactions between the two variables associated to the
positive and negative values of a real valued variable.
'),
set_parameter(fast, Rate),
compile_wgpac_impl(Wgpac).
compile_wgpac(WgpacSet) :-
biocham_command,
type(WgpacSet, {wgpac}),
doc('compiles a set of weak GPACs.'),
\+ (
member(Wgpac, WgpacSet),
\+ (
compile_wgpac(Wgpac)
compile_wgpac_impl(Wgpac)
)
).
:- dynamic(fast/1).
fast(1000).
fast_reaction_rate(K):-
biocham_command,
type(K, arithmetic_expression),
doc('
sets the fast reaction rate constant to K. The default value is 1000. This reaction constant is used in the reactions for computing the results of the sum and product GPAC blocks, and in the annihilation reactions between the two variables associated to the positive and negative values of a real valued variable.
'),
retractall(fast(_)),
assert(fast(K)).
compile_wgpac_impl(Y) :-
object(Y),
!,
print_message(informational, start(object, Y)).
debug(wgpac, 'Start object compilation of: ~w', [Y]).
compile_wgpac_impl(Wgpac) :-
Wgpac = Y :: B,
wgpac_well_formed(Wgpac),
!,
print_message(informational, start(named, Wgpac)),
debug(wgpac, 'Start named compilation of: ~w', [Wgpac]),
(
B = K,
number(K) %concentration(K)
......@@ -158,15 +138,15 @@ compile_wgpac_impl(Wgpac) :-
;
B = W1 + W2
->
print_message(informational, found('Sum box')),
debug(wgpac, 'Found Sum box', []),
(
wgpac_named(W1)
->
print_message(informational, found(1, named, W1)),
debug(wgpac, 'Found named at position 1: ~w', [W1]),
wgpac_name(W1, X1),
compile_wgpac_impl(W1)
;
print_message(informational, found(1, anonymous, W1)),
debug(wgpac, 'Found anonymous at position 1: ~w', [W1]),
get_fresh(N1),
atom_concat('x', N1, X1),
compile_wgpac_impl(X1 :: W1)
......@@ -174,11 +154,11 @@ compile_wgpac_impl(Wgpac) :-
(
wgpac_named(W2)
->
print_message(informational, found(2, named, W2)),
debug(wgpac, 'Found named at position 2: ~w', [W2]),
wgpac_name(W2, X2),
compile_wgpac_impl(W2)
;
print_message(informational, found(2, anonymous, W2)),
debug(wgpac, 'Found anonymous at position 2: ~w', [W2]),
get_fresh(N2),
atom_concat('x', N2, X2),
compile_wgpac_impl(X2 :: W2)
......@@ -190,15 +170,15 @@ compile_wgpac_impl(Wgpac) :-
;
B = W1 * W2
->
print_message(informational, found('Product box')),
debug(wgpac, 'Found Product box', []),
(
wgpac_named(W1)
->
print_message(informational, found(1, named, W1)),
debug(wgpac, 'Found named at position 1: ~w', [W1]),
wgpac_name(W1, X1),
compile_wgpac_impl(W1)
;
print_message(informational, found(1, anonymous, W1)),
debug(wgpac, 'Found anonymous at position 1: ~w', [W1]),
get_fresh(N1),
atom_concat('x', N1, X1),
compile_wgpac_impl(X1 :: W1)
......@@ -206,11 +186,11 @@ compile_wgpac_impl(Wgpac) :-
(
wgpac_named(W2)
->
print_message(informational, found(2, named, W2)),
debug(wgpac, 'Found named at position 2: ~w', [W2]),
wgpac_name(W2, X2),
compile_wgpac_impl(W2)
;
print_message(informational, found(2, anonymous, W2)),
debug(wgpac, 'Found anonymous at position 2: ~w', [W2]),
get_fresh(N2),
atom_concat('x', N2, X2),
compile_wgpac_impl(X2 :: W2)
......@@ -235,7 +215,7 @@ compile_wgpac_impl(Wgpac) :-
).
compile_wgpac_impl(Wgpac) :-
print_message(informational, start(anonymous, Wgpac)),
debug(wgpac, 'Start anonymous compilation of: ~w', [Wgpac]),
get_fresh(N),
atom_concat('x', N, Y),
wgpac_well_formed(Y :: Wgpac),
......@@ -254,33 +234,14 @@ compile_wgpac_impl(Wgpac) :-
\\end{example}
').
compile_wgpacs(WgpacSet) :-
biocham_command,
type(WgpacSet, {wgpac}),
doc('compiles a set of w-gpac.'),
\+ (
member(Wgpac, WgpacSet),
\+ (
compile_wgpac(Wgpac)
)
).
debug_iswgpac(W) :-
biocham_command,
(wgpac(W) -> write('WGPAC') ; write('not WGPAC')),
nl.
debug_iswgpacbox(B) :-
biocham_command,
(wgpacbox(B) -> write('WGPAC BOX') ; write('not WGPAC BOX')),
nl.
prolog:message(start(Type, Object)) -->
['Start ~w compilation of: ~w'-[Type, Object]].
prolog:message(found(Position, Type, Object)) -->
['Found ~w at position ~w: ~w'-[Type, Position, Object]].
prolog:message(found(Object)) -->
['Found ~w'-[Object]].
......@@ -3,6 +3,6 @@
:- begin_tests(wgpac).
test('compile_wgpac') :-
compile_wgpac((a :: integral integral (-1 * a))).
command(compile_wgpac((a :: integral integral (-1 * a)))).
:- end_tests(wgpac).
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment