Commit 40eccab0 authored by Sylvain Soliman's avatar Sylvain Soliman

Merge branch 'release/4.4.11'

parents 1aecead3 93551a89
......@@ -123,7 +123,7 @@ test_%: biocham_debug
echo "flag(slow_test, _, true), run_tests_and_halt('$*')." | ./biocham_debug
install_kernel: biocham $(KERNEL_DIR)/commands.js $(KERNEL_DIR)/commands.py $(WORKFLOWS_DIR)/workflows.js
- pip3 install --user $(JUPYTER_DIR)/kernel || pip install --user $(JUPYTER_DIR)/kernel
- python3 -m pip install --user $(JUPYTER_DIR)/kernel || pip install --user $(JUPYTER_DIR)/kernel
- jupyter kernelspec install --user --name=biocham $(KERNEL_DIR)
install_gui: $(WORKFLOWS_DIR)/workflows.js
......
......@@ -8,7 +8,7 @@
about/0
]).
version('4.4.10').
version('4.4.11').
copyright(
'Copyright (C) 2003-2020 Inria, EPI Lifeware, Saclay-Île de France, France'
......
FROM registry.gitlab.inria.fr/lifeware/biocham:v4.4.10
FROM registry.gitlab.inria.fr/lifeware/biocham:v4.4.11
{
"name": "gui",
"version": "4.4.10",
"version": "4.4.11",
"description": "biocham gui in jupyter notebook",
"main": "src/index.js",
"scripts": {
......
......@@ -118,6 +118,7 @@ commands = [
"list_graphs",
"list_influences",
"list_initial_state",
"list_input_species",
"list_isolated_vertices",
"list_last_state",
"list_locations",
......@@ -131,8 +132,15 @@ commands = [
"list_options",
"list_parameters",
"list_reactions",
"list_reactions_with_catalyst",
"list_reactions_with_inhibitor",
"list_reactions_with_product",
"list_reactions_with_reactant",
"list_reactions_with_species",
"list_rows",
"list_rules",
"list_sink_species",
"list_source_species",
"list_stable_states",
"list_tables",
"list_tscc_candidates",
......@@ -158,17 +166,22 @@ commands = [
"new_model",
"new_ode_system",
"numerical_simulation",
"ode_function",
"ode_parameter",
"ode_system",
"option",
"pac_learning",
"parameter",
"parametrize",
"pathway",
"pattern_reduction",
"place",
"plot",
"present",
"prolog",
"quit",
"rate_independence_reduction",
"rate_independence_reduction_inputs_sinks",
"reaction_graph",
"reaction_model",
"reduce_model",
......@@ -197,6 +210,7 @@ commands = [
"set_ode_system_name",
"set_p_m_rate",
"test_rate_independence",
"test_rate_independence_inputs_sinks",
"transition",
"tropicalize",
"undefined",
......
"""Example magic"""
__version__ = '4.4.10'
__version__ = '4.4.11'
:- module(
graph_properties,
[
pathway/2,
list_source_species/0,
list_input_species/0,
list_sink_species/0,
% API
pathway/3,
input_species/1,
source_species/1,
sink_species/1,
is_source/2,
is_input/2,
is_sink/2
]
).
:- doc('
Analysis of some graph properties of the current model.
').
pathway(Object1, Object2):-
biocham_command,
type(Object1, object),
type(Object2, object),
doc('Gives one reaction pathway from \\argument{Object1} to \\argument{Object2} if one exists in the directed reaction graph of the current model (for more complex queries, see next section on Computation Tree Logic model-checking).'),
(
pathway(Object1, Object2, Path)
->
reverse(Path, Reactions),
forall(member(R, Reactions), writeln(R))
;
writeln('there is no pathway')
).
pathway(Source, Target, Path):-
path([(Source, [Source])], [], [(Source, [Source])], Target, Path).
% Dijsktra algorithm with pathway memory
path([], [], _Forward, _Target, _Path):-
!,
fail.
path([], New, Forward, Target, Path):-
path(New, [], Forward, Target, Path).
path([A|Frontier], New, Forward, Target, Path):-
new_successors(A, Forward, List),
(
member((Target, Path), List)
->
true
;
append(List, New, New2),
append(List, Forward, Forward2),
path(Frontier, New2, Forward2, Target, Path)
).
new_successors(A, Forward, List):-
realsetof(B, graph_properties:new_successor(A, B, Forward), List).
new_successor((A, PathA), (B, [Reaction|PathA]), Forward):-
is_reactant(A, Reaction),
is_product(B, Reaction),
\+ member((B,_), Forward).
% Sources and Sinks
list_input_species:-
biocham_command,
doc('Lists the molecular species that are neither a non-strict-catalyst reaction product nor the target of an influence rule in the curent model.Strict catalysts, i.e. catalysts with same stoichiometry in left-hand and right side of reactions, are allowed as inputs.'),
input_species(Molecules),
writeln(Molecules).
list_source_species:-
biocham_command,
doc('Lists the molecular species that are neither a reaction product nor the target of an influence rule in the curent model.'),
source_species(Molecules),
writeln(Molecules).
list_sink_species:-
biocham_command,
doc('Lists the molecular species that are neither a reactant nor a positive source of an influence rule in the curent model.'),
sink_species(Molecules),
writeln(Molecules).
%API
:-devdoc('Prolog lists of graph sources and sinks.').
input_species(L):-
enumerate_molecules(Molecules),
realsetof(M, is_input(M, Molecules), L).
source_species(L):-
enumerate_molecules(Molecules),
realsetof(M, is_source(M, Molecules), L).
sink_species(L):-
enumerate_molecules(Molecules),
realsetof(M, is_sink(M, Molecules), L).
is_source(M, Molecules):-
member(M, Molecules),
\+ (
is_product(M,_)
),
\+ (
is_target(M,_)
).
is_input(M, Molecules):-
member(M, Molecules),
\+ (
is_strict_product(M,_)
),
\+ (
is_target(M,_)
).
is_sink(M, Molecules):-
member(M, Molecules),
\+ (
is_reactant(M,_)
),
\+ (
is_influence_source(M,_)
).
\ No newline at end of file
......@@ -15,7 +15,10 @@
influence/2,
compute_ode_for_influences/0,
print_influence/2,
substract_list/3
substract_list/3,
is_influence_source/2,
is_negative_source/2,
is_target/2
]
).
......@@ -451,3 +454,21 @@ inputs(
list_enumeration(PositiveInputList, PositiveInputEnum),
list_enumeration(NegativeInputList, NegativeInputEnum),
!.
is_influence_source(S, Influence):-
item([kind: influence, item: Influence]),
influence(Influence, [force: _, positive_inputs: Sources, negative_inputs:_, sign;_, output:_]),
member((_*S), Sources).
is_negative_source(S, Influence):-
item([kind: influence, item: Influence]),
influence(Influence, [force: _, positive_inputs: _, negative_inputs:Sources, sign;_, output:_]),
member((_*S), Sources).
is_target(S, Influence):-
item([kind: influence, item: Influence]),
influence(Influence, [force: _, positive_inputs: _, negative_inputs:_, sign;_, output: S]).
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# M7 Chemical SAT Solver\n",
"\n",
"* Deciding the satisfiability of a Boolean formula in conjunctive normal form is NP-complete\n",
"* How can we program a chemical SAT solver ? \n",
"\n",
"F. Fages, S. Soliman, Apr. 2020"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# \"Generate and Test\" Algorithm with Stochastic CRN\n",
"\n",
"A stochastic CRN can be used to enumerate random Boolean values for a variable"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parameter(k=1)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"MA(k) for _/a => a. % reactions with inhibitors cannot fire in presence of the inhibitor, here a"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"MA(k) for a => _."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"option(method:spn, stochastic_conversion:1)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"numerical_simulation.\n",
"plot."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1) Write a random generator of Boolean values for a vector of 3 variables a, b, c\n",
"\n",
"Write a stochastic CRN randomly sampling the Boolean values of a, b and c."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 2) Write a CRN to find values satisfying the formula (x⋁¬y)⋀(y⋁¬z)⋀(z⋁¬x)\n",
"\n",
"Use an event to stop the simulation when the formula is satisfied"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Guided Search Algorithm with Stochastic CRN\n",
"## Question 3) Improve your CRN to decrease the probability of moves of the variables that belong to satisfied clauses"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 4) Any idea to decide unsatisfiability?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 5) About the phase transition threshold in 3-SAT\n",
"\n",
"As seen in the class\n",
"* the density of a SAT instance is the ratio of the number of clauses divided by the number of variables\n",
"* a phase transition phenomenon is an asymptotic result showing the existence of a density threshold\n",
"* under the threshold the instances are almost surely satisfiable\n",
"* above the threshold the instances are almost surely unsatisfiable\n",
"* the hard instances are around the density threshold \n",
"\n",
"Can we observe that phenomenon with our CRN? Why?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Guided Search Algorithm by Continuous CRN\n",
"\n",
"We can see the SAT solving problem as a (continous) global optimization problem and try to solve it by gradient descent.\n",
"\n",
"The idea is to find an energy function $E$ that is minimal when all clauses are satisfied, and then to simply enforce that $$\\frac{dx}{dt} = -\\frac{\\partial E}{\\partial x}$$\n",
"\n",
"For a SAT problem involving variables $x_i\\in [0, 1], 1\\leq i\\leq N$ and clauses $C_j, 1\\leq j\\leq M$ (with $C_{ji} = 1$ if $x_i$ appears positively in $C_j$, $C_{ji} = -1$ if $x_i$ appears negatively, and $0$ otherwise), we will define our energy function as a sum of squares of sub-energies for each clause.\n",
"\n",
"$$E = \\sum_{1\\leq j\\leq M}K_j^2$$\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 6) Write $K_j$\n",
"\n",
"Define (formally) $K_j$ as a function of the $C_{ji}$ and of the $x_i$, such that $K_j = 0$ iff clause $j$ is satisfied, and $K_j = 2^N$ if all $N$ variables appear in clause $j$ and are currently at the _wrong_ value.\n",
"\n",
"One might want to define $s_i\\in[-1, 1]$ as a function of $x_i\\in[0, 1]$ and then $K_j$ as a function of the $s_i$ for ease of writing."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 7) Obtain $dx_i/dt$\n",
"\n",
"Obtain the formal expression for $\\displaystyle\\frac{dx}{dt}$ (if you have used $s_i$ just note that $\\frac{\\partial E}{\\partial x}=\\frac{\\partial E}{\\partial x}\\frac{\\partial s}{\\partial x}$)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 8) Implement on the above example (x⋁¬y)⋀(y⋁¬z)⋀(z⋁¬x)\n",
"\n",
"Using the commands:\n",
"`new_ode_system`, `init` (to set $x_1, x_2$ and $x_3$ initial state to 0.5), `ode_parameter` (to set the $c_ji$ corresponding to our 3 clauses), `ode_function` (for the $k_j$ and $s_i$) and `add_ode` (to add the above $dx_i/dt$)\n",
"\n",
"Run a numerical simulation and plot the $x_i$ to see the result.\n",
"Experiment with different initial states, and variants of the problem (changing only the $c_{ji}$), what do you observe? [please leave all results and remarks *in* the notebook!]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 9) Improving the search\n",
"\n",
"To avoid getting stuck in some local minima, we can add *Lagrange multipliers* $a_j, 1\\leq j\\leq M$ so that the energy becomes $$E = \\sum_{1\\leq j\\leq M}a_j K_j^2$$\n",
"These are new variables that will have an exponential increase proportional to $K_j$.\n",
"\n",
"Add the 3 new variables and their ODEs with `add_ode`, change also the existing model accordingly.\n",
"Do you notice any difference? What can you say about the steadiness and stability of the initial state with all $x_i$ equal to 0.5?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],