Repository: Kappa-Dev/KappaTools (language: python)

Issue:
Small-than implementation in counters as translation into new "inverted counter"
Allows `<=` tests in a agent counter. 

Using `<=` will enable in parallel a hidden  _inverted_ counter where the  `>=` test will be made.
Counter logic is planned to be revamped to allow this naturally.

Example of use:

```
%agent: A(c{=0 / += 7})
%agent: B()

'rule_a' A(c{<=2}) -> A(c{+=1}) @ 1
'rule_b' A(c{>=5}) -> A(c{-=1}) @ 1
'rule_c' A(c{=3}) -> A(c{+=1}) @ 1
'rule_aa' A(c{<=1}),. -> ., B() @ 0.2

%init: 10 A(c{=0})
%init: 10 A(c{=7})

// %obs: 'A' |A()|
%obs: 'B' |B()|
%obs: 'A0' |A(c{=0})|
%obs: 'A1' |A(c{=1})|
%obs: 'A2' |A(c{=2})|
%obs: 'A3' |A(c{=3})|
%obs: 'A4' |A(c{=4})|
%obs: 'A5' |A(c{=5})|
%obs: 'A6' |A(c{=6})|
%obs: 'A7' |A(c{=7})|
```

Here, a counter `c__inverted` is added onto agent `A`, which manages the `<=` tests.


Discussion / hints:
Does this change anything besides adding the "lesser than" testing capacity?

I maintain a parser/analyzer at https://github.com/hmedina/KaSaAn which I'll need to update, so I'm just wondering if there's more to it or just this.
> Does this change anything besides adding the "lesser than" testing capacity?
> 
> I maintain a parser/analyzer at https://github.com/hmedina/KaSaAn which I'll need to update, so I'm just wondering if there's more to it or just this.

Hey :-)

Not sure how you manage counters there. If there are no `<=` tests in the model, everything will behave the same.

It seems like KaSaAn is based on parsing snapshots ?
As for now `<=` is syntaxic sugar for adding a new counter, a new counter ending in `__inverted` will appear in the snapshots if `<=` is used.

It is likely we add a new logic that will remove this new counter for the rule condition to work.

Does that answer your question?
Hey there!

Ok, if snapshots won't contain this new construct, only rules, then I don't need to update my parsing yet, as the "real" thing in the snapshot should parse fine. Will contact maps have the rule's definition (`<=`), or the generated new agent (`__inverted`)?
In this PR, after the parsing of the `.ka`, the `<=` are gone and replaced by the use of the `__inverted` agent, which will then show up everywhere, including the contact maps.

Everything should work fine on your end.

Fix patch:
diff --git a/.ocamldebug b/.ocamldebug
index f91b82453..03aea3a4a 100644
--- a/.ocamldebug
+++ b/.ocamldebug
@@ -7,20 +7,20 @@ load_printer "easy_format.cma"
 load_printer "biniou.cma"
 load_printer "yojson.cma"
 load_printer "logs.cma"
-load_printer "kappa_generic_toolset.cma"
-load_printer "kappa_mixtures.cma"
+load_printer "kappa_data_structures.cma"
+load_printer "kappa_site_graphs.cma"
 load_printer "kappa_terms.cma"
 load_printer "kappa_runtime.cma"
 
-install_printer Kappa_generic_toolset.Mods.IntSetMap.Set.print
-install_printer Kappa_generic_toolset.Mods.Int2SetMap.Set.print
-install_printer Kappa_generic_toolset.Mods.StringSetMap.Set.print
-install_printer Kappa_generic_toolset.Mods.CharSetMap.Set.print
-install_printer Kappa_generic_toolset.IntCollection.print
-install_printer Kappa_generic_toolset.ValMap.print
-install_printer Kappa_generic_toolset.Renaming.print_full
-install_printer Kappa_generic_toolset.Random_tree.debug_print
-install_printer Kappa_generic_toolset.Operator.DepSet.print
-install_printer Kappa_mixtures.Edges.debug_print
+install_printer Kappa_data_structures.Mods.IntSetMap.Set.print
+install_printer Kappa_data_structures.Mods.Int2SetMap.Set.print
+install_printer Kappa_data_structures.Mods.StringSetMap.Set.print
+install_printer Kappa_data_structures.Mods.CharSetMap.Set.print
+install_printer Kappa_data_structures.IntCollection.print
+install_printer Kappa_data_structures.ValMap.print
+install_printer Kappa_data_structures.Renaming.print_full
+install_printer Kappa_data_structures.Random_tree.debug_print
+install_printer Kappa_data_structures.Operator.DepSet.print
+install_printer Kappa_site_graphs.Edges.debug_print
 install_printer Kappa_terms.Matching.debug_print
 install_printer Kappa_runtime.Rule_interpreter.debug_print
diff --git a/core/KaSa_rep/abstract_domains/mvbdu/dune b/core/KaSa_rep/abstract_domains/mvbdu/dune
index a26bb9ce1..b1d124a9a 100644
--- a/core/KaSa_rep/abstract_domains/mvbdu/dune
+++ b/core/KaSa_rep/abstract_domains/mvbdu/dune
@@ -14,4 +14,4 @@
    -open
    Kappa_kasa_kastor_toolset
    -open
-   Kappa_generic_toolset)))
+   Kappa_data_structures)))
diff --git a/core/KaSa_rep/abstract_domains/numerical_domains/dune b/core/KaSa_rep/abstract_domains/numerical_domains/dune
index 7e5d94465..0e881ba1d 100644
--- a/core/KaSa_rep/abstract_domains/numerical_domains/dune
+++ b/core/KaSa_rep/abstract_domains/numerical_domains/dune
@@ -14,6 +14,6 @@
    -open
    Kappa_kasa_kastor_toolset
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_kasa_frontend)))
diff --git a/core/KaSa_rep/backend/dune b/core/KaSa_rep/backend/dune
index c5c4bd8c2..25244b1f7 100644
--- a/core/KaSa_rep/backend/dune
+++ b/core/KaSa_rep/backend/dune
@@ -20,7 +20,7 @@
    -open
    Kappa_logging
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_kasa_remanent_state
    -open
diff --git a/core/KaSa_rep/counting_enumerating_species/dune b/core/KaSa_rep/counting_enumerating_species/dune
index 3d2268303..37f4a87f9 100644
--- a/core/KaSa_rep/counting_enumerating_species/dune
+++ b/core/KaSa_rep/counting_enumerating_species/dune
@@ -14,6 +14,6 @@
   -open
   Kappa_logging
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_kasa_kastor_toolset))
diff --git a/core/KaSa_rep/export/dune b/core/KaSa_rep/export/dune
index 06dd1eeb8..e72861f08 100644
--- a/core/KaSa_rep/export/dune
+++ b/core/KaSa_rep/export/dune
@@ -19,7 +19,7 @@
   -open
   Kappa_logging
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_errors
   -open
@@ -35,7 +35,7 @@
   -open
   Kappa_profiling
   -open
-  Kappa_mixtures
+  Kappa_site_graphs
   -open
   Kappa_influence_map
   -open
diff --git a/core/KaSa_rep/flow/dune b/core/KaSa_rep/flow/dune
index e4644deea..b36b14ecd 100644
--- a/core/KaSa_rep/flow/dune
+++ b/core/KaSa_rep/flow/dune
@@ -6,7 +6,7 @@
   -open
   Kappa_kasa_frontend
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_parameters
   -open
diff --git a/core/KaSa_rep/frontend/dune b/core/KaSa_rep/frontend/dune
index 8fb1f74a5..046545bd9 100644
--- a/core/KaSa_rep/frontend/dune
+++ b/core/KaSa_rep/frontend/dune
@@ -8,7 +8,7 @@
    -open
    Kappa_kasa_kastor_toolset
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_parameters
    -open
diff --git a/core/KaSa_rep/influence_map/dune b/core/KaSa_rep/influence_map/dune
index f3f50e198..0dcad4048 100644
--- a/core/KaSa_rep/influence_map/dune
+++ b/core/KaSa_rep/influence_map/dune
@@ -22,6 +22,6 @@
   -open
   Kappa_kasa_kastor_toolset
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_terms))
diff --git a/core/KaSa_rep/main/dune b/core/KaSa_rep/main/dune
index 4b83362bb..0035be040 100644
--- a/core/KaSa_rep/main/dune
+++ b/core/KaSa_rep/main/dune
@@ -13,9 +13,9 @@
    -w
    @a
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/KaSa_rep/more_datastructures/dune b/core/KaSa_rep/more_datastructures/dune
index e27524c3a..f0853b260 100644
--- a/core/KaSa_rep/more_datastructures/dune
+++ b/core/KaSa_rep/more_datastructures/dune
@@ -19,4 +19,4 @@
    -open
    Kappa_errors
    -open
-   Kappa_generic_toolset)))
+   Kappa_data_structures)))
diff --git a/core/KaSa_rep/reachability_analysis/dune b/core/KaSa_rep/reachability_analysis/dune
index 6b29adafd..04d210a3b 100644
--- a/core/KaSa_rep/reachability_analysis/dune
+++ b/core/KaSa_rep/reachability_analysis/dune
@@ -12,7 +12,7 @@
   -open
   Kappa_kasa_frontend
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_parameters
   -open
diff --git a/core/KaSa_rep/remanent_state/dune b/core/KaSa_rep/remanent_state/dune
index 0b823fd43..d547afa03 100644
--- a/core/KaSa_rep/remanent_state/dune
+++ b/core/KaSa_rep/remanent_state/dune
@@ -20,7 +20,7 @@
    -open
    Kappa_kasa_kastor_toolset
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_kasa_site_graphs
    -open
@@ -32,7 +32,7 @@
    -open
    Kappa_profiling
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_flow_analysis
    -open
diff --git a/core/KaSa_rep/site_graphs/dune b/core/KaSa_rep/site_graphs/dune
index 1d52e4489..ad31ed95f 100644
--- a/core/KaSa_rep/site_graphs/dune
+++ b/core/KaSa_rep/site_graphs/dune
@@ -16,6 +16,6 @@
    -open
    Kappa_logging
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_kasa_type_interface)))
diff --git a/core/KaSa_rep/type_interface/dune b/core/KaSa_rep/type_interface/dune
index b1135bf18..f1743b807 100644
--- a/core/KaSa_rep/type_interface/dune
+++ b/core/KaSa_rep/type_interface/dune
@@ -2,4 +2,4 @@
  (name kappa_kasa_type_interface)
  (libraries yojson kappa-library.mixtures)
  (flags
-  (:standard -w @a -open Kappa_generic_toolset -open Kappa_mixtures)))
+  (:standard -w @a -open Kappa_data_structures -open Kappa_site_graphs)))
diff --git a/core/agents/dune b/core/agents/dune
index 08a7903d5..739b8158a 100644
--- a/core/agents/dune
+++ b/core/agents/dune
@@ -3,7 +3,7 @@
  (modules agent_common app_args)
  (libraries logs.fmt lwt.unix kappa-library.generic)
  (flags
-  (:standard -w @a -open Kappa_generic_toolset)))
+  (:standard -w @a -open Kappa_data_structures)))
 
 (executable
  (name KaStor)
@@ -14,7 +14,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_runtime
    -open
@@ -43,7 +43,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_cli
    -open
@@ -60,7 +60,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_grammar
    -open
@@ -84,7 +84,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_grammar
    -open
diff --git a/core/api/dune b/core/api/dune
index 79d46706b..b4450e4dd 100644
--- a/core/api/dune
+++ b/core/api/dune
@@ -11,9 +11,9 @@
    -w
    +a-40-42
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/api/switchman_client.mli b/core/api/switchman_client.mli
index 91811af74..ad62b5d01 100644
--- a/core/api/switchman_client.mli
+++ b/core/api/switchman_client.mli
@@ -10,8 +10,8 @@ object
 
   method file_catalog :
     ( Kappa_grammar.Kfiles.catalog_item list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method file_create :
@@ -19,38 +19,38 @@ object
     string ->
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method file_delete :
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method file_get :
     string ->
     ( string * int,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method file_move :
     int ->
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method file_update :
     string ->
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_constraints_list :
@@ -59,42 +59,42 @@ object
         Kappa_kasa_type_interface.Public_data.lemma
         list)
       list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_contact_map :
     Kappa_kasa_type_interface.Public_data.accuracy_level option ->
     ( Yojson.Basic.t,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_dead_agents :
     ( Kappa_kasa_type_interface.Public_data.dead_agents,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_dead_rules :
     ( Kappa_kasa_type_interface.Public_data.rule list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_influence_map_node_at :
     filename:string ->
-    Kappa_generic_toolset.Loc.position ->
+    Kappa_data_structures.Loc.position ->
     ( (int, int) Kappa_kasa_type_interface.Public_data.influence_node option,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_influence_map_raw :
     Kappa_kasa_type_interface.Public_data.accuracy_level option ->
     ( string,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_initial_node :
@@ -102,8 +102,8 @@ object
         Kappa_kasa_type_interface.Public_data.var )
       Kappa_kasa_type_interface.Public_data.influence_node
       option,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_local_influence_map :
@@ -121,8 +121,8 @@ object
         Kappa_kasa_type_interface.Public_data.influence_node
         option
       * Kappa_kasa_type_interface.Public_data.influence_map,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_next_node :
@@ -131,8 +131,8 @@ object
         Kappa_kasa_type_interface.Public_data.var )
       Kappa_kasa_type_interface.Public_data.influence_node
       option,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_nodes_of_influence_map :
@@ -142,14 +142,14 @@ object
           Kappa_kasa_type_interface.Public_data.var )
         Kappa_kasa_type_interface.Public_data.influence_node
         list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_non_weakly_reversible_transitions :
     ( (Kappa_kasa_type_interface.Public_data.rule * (string * string) list) list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_potential_polymers :
@@ -158,8 +158,8 @@ object
     ( Kappa_kasa_type_interface.Public_data.accuracy_level
       * Kappa_kasa_type_interface.Public_data.accuracy_level
       * Kappa_kasa_type_interface.Public_data.scc,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method get_previous_node :
@@ -168,22 +168,22 @@ object
         Kappa_kasa_type_interface.Public_data.var )
       Kappa_kasa_type_interface.Public_data.influence_node
       option,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method init_static_analyser :
     Kappa_grammar.Ast.parsing_compil ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method init_static_analyser_raw :
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method private message :
@@ -191,24 +191,24 @@ object
     'a handle ->
     (Buffer.t -> unit) ->
     ( 'a,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method project_overwrite :
     string ->
     Kappa_grammar.Ast.parsing_compil ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method project_parse :
     patternSharing:Kappa_terms.Pattern.sharing_level ->
-    (string * Kappa_generic_toolset.Nbr.t) list ->
+    (string * Kappa_data_structures.Nbr.t) list ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method secret_get_pos_of_rules_and_vars :
@@ -219,122 +219,122 @@ object
   method secret_simulation_load :
     Kappa_terms.Pattern.sharing_level ->
     Kappa_grammar.Ast.parsing_compil ->
-    (string * Kappa_generic_toolset.Nbr.t) list ->
+    (string * Kappa_data_structures.Nbr.t) list ->
     unit Api.result Lwt.t
 
   method simulation_catalog_din :
     ( string list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_catalog_file_line :
     ( string list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_catalog_snapshot :
     ( string list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_continue :
     string ->
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_delete :
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_detail_din :
     string ->
     ( Kappa_runtime.Data.din,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_detail_file_line :
     string ->
     ( string list,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_detail_log_message :
     ( string,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_detail_plot :
     Api_types_j.plot_parameter ->
     ( Kappa_runtime.Data.plot,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_detail_snapshot :
     string ->
     ( Kappa_runtime.Data.snapshot,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_efficiency :
     ( Kappa_runtime.Counter.Efficiency.t,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_info :
     ( Api_types_t.simulation_info,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_intervention :
     string ->
     ( string,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_outputs_zip :
-    ( Kappa_generic_toolset.Bigbuffer.bigstring,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+    ( Kappa_data_structures.Bigbuffer.bigstring,
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_parameter :
     ( Api_types_t.simulation_parameter,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_pause :
     ( unit,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_raw_trace :
     ( string,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 
   method simulation_start :
     Api_types_j.simulation_parameter ->
     ( Api_types_t.simulation_artifact,
-      Kappa_generic_toolset.Result_util.message list )
-    Kappa_generic_toolset.Result_util.t
+      Kappa_data_structures.Result_util.message list )
+    Kappa_data_structures.Result_util.t
     Lwt.t
 end
 
diff --git a/core/cflow/dune b/core/cflow/dune
index d5e83955f..b9d1f1da6 100644
--- a/core/cflow/dune
+++ b/core/cflow/dune
@@ -9,9 +9,9 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/classical_graphs/dune b/core/classical_graphs/dune
index fc8e4318f..2cafdc68f 100644
--- a/core/classical_graphs/dune
+++ b/core/classical_graphs/dune
@@ -2,4 +2,4 @@
  (name kappa_classical_graphs)
  (libraries yojson kappa-library.generic kappa_logging)
  (flags
-  (:standard -w @a -open Kappa_generic_toolset -open Kappa_logging)))
+  (:standard -w @a -open Kappa_data_structures -open Kappa_logging)))
diff --git a/core/cli/dune b/core/cli/dune
index d8ccb6aae..3e939b5fd 100644
--- a/core/cli/dune
+++ b/core/cli/dune
@@ -18,9 +18,9 @@
    -open
    Kappa_version
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/dataStructures/dune b/core/dataStructures/dune
index fc931a532..580f8eb39 100644
--- a/core/dataStructures/dune
+++ b/core/dataStructures/dune
@@ -1,5 +1,5 @@
 (library
- (name kappa_generic_toolset)
+ (name kappa_data_structures)
  (libraries unix yojson result logs stdlib-shims bigarray camlp-streams)
  (public_name kappa-library.generic)
  (flags
diff --git a/core/error_handlers/dune b/core/error_handlers/dune
index b0d549556..55674c7cc 100644
--- a/core/error_handlers/dune
+++ b/core/error_handlers/dune
@@ -9,7 +9,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_logging
    -open
diff --git a/core/grammar/counters_compiler.ml b/core/grammar/counters_compiler.ml
index e3302430a..9aafe0b39 100644
--- a/core/grammar/counters_compiler.ml
+++ b/core/grammar/counters_compiler.ml
@@ -316,7 +316,7 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
   let rec split_for_each_counter_var_value_sites (ids : Mods.StringSet.t)
       (counter_defs : Ast.counter list) :
       Ast.site list -> (Ast.site list * (string * int) list) list = function
-    | [] -> [[],[]]
+    | [] -> [ [], [] ]
     | s :: t ->
       combinations_of_var_setup
         (split_for_each_counter_var_value_sites ids counter_defs t)
@@ -337,7 +337,7 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
   in
   let rec split_for_each_counter_var_value_mixture (ids : Mods.StringSet.t) :
       Ast.agent list -> (Ast.agent list * (string * int) list) list = function
-    | [] -> [[],[]]
+    | [] -> [ [], [] ]
     | ast_agent :: t ->
       combinations_of_var_setup
         (split_for_each_counter_var_value_mixture ids t)
@@ -434,8 +434,7 @@ let split_counter_variables_into_separate_rules ~warning rules signatures =
 
   List.fold_left
     (fun acc (rule_name, rule_annoted) ->
-        (split_for_each_counter_var_value_rule rule_name rule_annoted)
- @ acc)
+      split_for_each_counter_var_value_rule rule_name rule_annoted @ acc)
     [] rules
   (* TODO: is rev relevant here? *)
   |> List.rev
@@ -474,11 +473,11 @@ let make_counter_agent sigs (is_first, (dst, ra_erased)) (is_last, equal) i j
   let before_switch =
     if is_first then
       if created then
-         LKappa.Linked i
+        LKappa.Linked i
       else if ra_erased then
-         LKappa.Erased
+        LKappa.Erased
       else
-         LKappa.Maintained
+        LKappa.Maintained
     else
       LKappa.Maintained
   in
@@ -599,7 +598,7 @@ let rec erase_incr (sigs : Signature.s) (i : int) (incrs : LKappa.rule_mixture)
 (** Returns mixtures for agent with site changed from counter to port, as well as new [link_nb] after previous additions
  * Used by [compile_counter_in_rule_agent]*)
 let counter_becomes_port (sigs : Signature.s) (ra : LKappa.rule_agent)
-    (p_id : int) (counter : Ast.counter) (start_link_nb : int) :
+    (port_id : int) (counter : Ast.counter) (start_link_nb : int) :
     (LKappa.rule_mixture * Raw_mixture.t) * int =
   (* Returns positive part of value *)
   let positive_part (i : int) : int =
@@ -638,7 +637,7 @@ let counter_becomes_port (sigs : Signature.s) (ra : LKappa.rule_agent)
   let start_link_for_created : int = start_link_nb + test + 1 in
   let link_for_erased : int = start_link_nb + abs delta in
   let ag_info : (int * int) * bool =
-    (p_id, ra.LKappa.ra_type), ra.LKappa.ra_erased
+    (port_id, ra.LKappa.ra_type), ra.LKappa.ra_erased
   in
 
   let test_incr : LKappa.rule_mixture =
@@ -675,7 +674,7 @@ let counter_becomes_port (sigs : Signature.s) (ra : LKappa.rule_agent)
   in
   let counter_agent_info = Signature.get_counter_agent_info sigs in
   let port_b : int = fst counter_agent_info.ports in
-  ra.LKappa.ra_ports.(p_id) <-
+  ra.LKappa.ra_ports.(port_id) <-
     ( (LKappa.LNK_VALUE (start_link_nb, (port_b, counter_agent_info.id)), loc),
       switch );
   let new_link_nb : int = start_link_nb + 1 + test + positive_part delta in
@@ -715,7 +714,7 @@ let compile_counter_in_raw_agent (sigs : Signature.s)
   let raw_agent : Raw_mixture.agent = raw_agent_.agent in
   let ports : Raw_mixture.link array = raw_agent.Raw_mixture.a_ports in
   Tools.array_fold_lefti
-    (fun p_id (acc, lnk_nb) -> function
+    (fun port_id (acc, lnk_nb) -> function
       | None -> acc, lnk_nb
       | Some (c, _) ->
         (match c.Ast.counter_test with
@@ -739,7 +738,7 @@ let compile_counter_in_raw_agent (sigs : Signature.s)
               agent_name c.Ast.counter_name
           | Ast.CEQ j ->
             let p = Raw_mixture.VAL lnk_nb in
-            let () = ports.(p_id) <- p in
+            let () = ports.(port_id) <- p in
             let incrs = add_incr 0 lnk_nb (lnk_nb + j) (j + 1) true sigs in
             acc @ incrs, lnk_nb + j + 1)))
     ([], lnk_nb) raw_agent_.counters
@@ -816,9 +815,9 @@ let compile_counter_in_rule (sigs : Signature.s)
     ( List.rev_map (fun rule_agent_ -> rule_agent_.agent) (List.rev mix),
       List.rev_map (fun raw_agent_ -> raw_agent_.agent) (List.rev created) )
 
-let rule_agent_with_max_counter sigs c ((agent_name, _) as ag_ty) :
+let rule_agent_with_max_counter sigs c ((agent_name, _) as agent_type) :
     LKappa.rule_mixture =
-  let ag_id = Signature.num_of_agent ag_ty sigs in
+  let ag_id = Signature.num_of_agent agent_type sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
   let ports =
@@ -847,11 +846,11 @@ let rule_agent_with_max_counter sigs c ((agent_name, _) as ag_ty) :
   in
   ra :: incrs
 
-let counter_perturbation sigs c ag_ty =
+let counter_perturbation sigs c agent_type =
   let annot = Loc.get_annot c.Ast.counter_name in
   let filename = [ Primitives.Str_pexpr ("counter_perturbation.ka", annot) ] in
   let stop_message =
-    "Counter " ^ Loc.v c.Ast.counter_name ^ " of agent " ^ Loc.v ag_ty
+    "Counter " ^ Loc.v c.Ast.counter_name ^ " of agent " ^ Loc.v agent_type
     ^ " reached maximum"
   in
   let mods =
@@ -862,7 +861,7 @@ let counter_perturbation sigs c ag_ty =
     ]
   in
   let val_of_counter =
-    Alg_expr.KAPPA_INSTANCE (rule_agent_with_max_counter sigs c ag_ty)
+    Alg_expr.KAPPA_INSTANCE (rule_agent_with_max_counter sigs c agent_type)
   in
   let pre =
     Alg_expr.COMPARE_OP
@@ -871,7 +870,7 @@ let counter_perturbation sigs c ag_ty =
         (Alg_expr.CONST (Nbr.I 1), annot) )
   in
   ( None,
-    Some (pre, Loc.get_annot ag_ty),
+    Some (pre, Loc.get_annot agent_type),
     mods,
     Some (Loc.annot_with_dummy Alg_expr.FALSE) )
 
@@ -879,13 +878,14 @@ let counters_perturbations sigs ast_sigs =
   List.fold_left
     (List.fold_left (fun acc -> function
        | Ast.Absent _ -> acc
-       | Ast.Present (ag_ty, sites, _) ->
+       | Ast.Present (agent_type, sites, _) ->
          List.fold_left
            (fun acc' site ->
              match site with
              | Ast.Port _ -> acc'
              | Ast.Counter c ->
-               (counter_perturbation sigs c ag_ty, Loc.get_annot ag_ty) :: acc')
+               (counter_perturbation sigs c agent_type, Loc.get_annot agent_type)
+               :: acc')
            acc sites))
     [] ast_sigs
 
@@ -910,13 +910,13 @@ let annotate_dropped_counters sign ast_counters ra arity agent_name aux =
     List.fold_left
       (fun pset c ->
         let port_name = c.Ast.counter_name in
-        let p_id = Signature.num_of_site ~agent_name port_name sign in
+        let port_id = Signature.num_of_site ~agent_name port_name sign in
         let () =
-          match Signature.counter_of_site_id p_id sign with
+          match Signature.counter_of_site_id port_id sign with
           | None -> LKappa.raise_counter_misused agent_name c.Ast.counter_name
           | Some _ -> ()
         in
-        let pset' = Mods.IntSet.add p_id pset in
+        let pset' = Mods.IntSet.add port_id pset in
         let () =
           if pset == pset' then
             LKappa.raise_several_occurence_of_site agent_name c.Ast.counter_name
@@ -924,18 +924,18 @@ let annotate_dropped_counters sign ast_counters ra arity agent_name aux =
         let () = raise_if_modification c.Ast.counter_delta in
         let () =
           match aux with
-          | Some f -> f p_id
+          | Some f -> f port_id
           | None -> ()
         in
-        ra_counters.(p_id) <- Some (c, LKappa.Erased);
+        ra_counters.(port_id) <- Some (c, LKappa.Erased);
         pset')
       Mods.IntSet.empty ast_counters
   in
   { agent = ra; counters = ra_counters }
 
-let annotate_edit_counters sigs ((agent_name, _) as ag_ty) counters ra
+let annotate_edit_counters sigs ((agent_name, _) as agent_type) counters ra
     add_link_contact_map =
-  let ag_id = Signature.num_of_agent ag_ty sigs in
+  let ag_id = Signature.num_of_agent agent_type sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
   let ra_counters = Array.make arity None in
@@ -948,27 +948,27 @@ let annotate_edit_counters sigs ((agent_name, _) as ag_ty) counters ra
     List.fold_left
       (fun pset c ->
         let port_name = c.Ast.counter_name in
-        let p_id = Signature.num_of_site ~agent_name port_name sign in
+        let port_id = Signature.num_of_site ~agent_name port_name sign in
         let () =
-          match Signature.counter_of_site_id p_id sign with
+          match Signature.counter_of_site_id port_id sign with
           | None -> LKappa.raise_counter_misused agent_name c.Ast.counter_name
           | Some _ -> ()
         in
-        let pset' = Mods.IntSet.add p_id pset in
+        let pset' = Mods.IntSet.add port_id pset in
         let () =
           if pset == pset' then
             LKappa.raise_several_occurence_of_site agent_name c.Ast.counter_name
         in
-        let () = register_counter_modif p_id in
-        let () = ra_counters.(p_id) <- Some (c, LKappa.Maintained) in
+        let () = register_counter_modif port_id in
+        let () = ra_counters.(port_id) <- Some (c, LKappa.Maintained) in
         pset')
       Mods.IntSet.empty counters
   in
   { agent = ra; counters = ra_counters }
 
-let annotate_counters_with_diff sigs ((agent_name, loc) as ag_ty) lc rc ra
+let annotate_counters_with_diff sigs ((agent_name, loc) as agent_type) lc rc ra
     add_link_contact_map =
-  let ag_id = Signature.num_of_agent ag_ty sigs in
+  let ag_id = Signature.num_of_agent agent_type sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
   let register_counter_modif c c_id =
@@ -1015,26 +1015,36 @@ let annotate_counters_with_diff sigs ((agent_name, loc) as ag_ty) lc rc ra
          ("Counters in " ^ agent_name ^ " should have tests by now", loc));
   { agent = ra; counters = ra_counters }
 
-let annotate_created_counters sigs ((agent_name, _) as ag_ty) counters
+let annotate_created_counters sigs ((agent_name, _) as agent_type) counter_list
     add_link_contact_map ra =
-  let ag_id = Signature.num_of_agent ag_ty sigs in
-  let sign = Signature.get sigs ag_id in
-  let arity = Signature.arity sigs ag_id in
-  let ra_counters = Array.make arity None in
+  let agent_id : int = Signature.num_of_agent agent_type sigs in
+  let agent_signature : Signature.t = Signature.get sigs agent_id in
+  let arity : int = Signature.arity sigs agent_id in
+  let ra_counters : (Ast.counter * LKappa.switching) option array =
+    Array.make arity None
+  in
 
   (* register all counters (specified or not) with min value *)
   Array.iteri
-    (fun p_id _ ->
-      match Signature.counter_of_site_id p_id sign with
-      | Some (min, _) ->
-        let c_name = Signature.site_of_num p_id sign in
+    (fun port_id _ ->
+      match Signature.counter_of_site_id port_id agent_signature with
+      | Some (counter_min, counter_max) ->
+        let counter_name = Signature.site_of_num port_id agent_signature in
+        let default_init_value =
+          if Signature.is_inverted_counter counter_name then
+            counter_max
+          else
+            counter_min
+        in
         (try
-           let c =
+           (* find counter matching port *)
+           let c : Ast.counter =
              List.find
-               (fun c' -> String.compare (Loc.v c'.Ast.counter_name) c_name = 0)
-               counters
+               (fun c' ->
+                 String.compare (Loc.v c'.Ast.counter_name) counter_name = 0)
+               counter_list
            in
-           ra_counters.(p_id) <-
+           ra_counters.(port_id) <-
              Some
                ( {
                    Ast.counter_name = c.Ast.counter_name;
@@ -1043,11 +1053,12 @@ let annotate_created_counters sigs ((agent_name, _) as ag_ty) counters
                  },
                  LKappa.Maintained )
          with Not_found ->
-           ra_counters.(p_id) <-
+           ra_counters.(port_id) <-
              Some
                ( {
-                   Ast.counter_name = c_name, Loc.dummy;
-                   Ast.counter_test = Some (Ast.CEQ min, Loc.dummy);
+                   Ast.counter_name = counter_name, Loc.dummy;
+                   Ast.counter_test =
+                     Some (Ast.CEQ default_init_value, Loc.dummy);
                    Ast.counter_delta = 0, Loc.dummy;
                  },
                  LKappa.Maintained ))
@@ -1057,23 +1068,25 @@ let annotate_created_counters sigs ((agent_name, _) as ag_ty) counters
   let register_counter_modif c_id =
     let counter_agent_info = Signature.get_counter_agent_info sigs in
     let port_b = fst counter_agent_info.ports in
-    add_link_contact_map ag_id c_id counter_agent_info.id port_b
+    add_link_contact_map agent_id c_id counter_agent_info.id port_b
   in
   let _ : Mods.IntSet.t =
     List.fold_left
       (fun pset c ->
         let port_name = c.Ast.counter_name in
-        let p_id = Signature.num_of_site ~agent_name port_name sign in
-        match Signature.counter_of_site_id p_id sign with
+        let port_id =
+          Signature.num_of_site ~agent_name port_name agent_signature
+        in
+        match Signature.counter_of_site_id port_id agent_signature with
         | None -> LKappa.raise_counter_misused agent_name c.Ast.counter_name
         | Some _ ->
           ();
-          let pset' = Mods.IntSet.add p_id pset in
+          let pset' = Mods.IntSet.add port_id pset in
           if pset == pset' then
             LKappa.raise_several_occurence_of_site agent_name c.Ast.counter_name;
-          register_counter_modif p_id;
-          ra_counters.(p_id) <- Some (c, LKappa.Maintained);
+          register_counter_modif port_id;
+          ra_counters.(port_id) <- Some (c, LKappa.Maintained);
           pset')
-      Mods.IntSet.empty counters
+      Mods.IntSet.empty counter_list
   in
   { agent = ra; counters = ra_counters }
diff --git a/core/grammar/dune b/core/grammar/dune
index 90d0f3cae..97ed1526c 100644
--- a/core/grammar/dune
+++ b/core/grammar/dune
@@ -6,9 +6,9 @@
    -w
    @a-40-42
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/grammar/lKappa_compiler.ml b/core/grammar/lKappa_compiler.ml
index f6631c926..48bed3f56 100644
--- a/core/grammar/lKappa_compiler.ml
+++ b/core/grammar/lKappa_compiler.ml
@@ -133,7 +133,7 @@ let build_link ?warn_on_swap sigs ?contact_map pos i ag_ty p_id switch
   )
 
 let annotate_dropped_agent ~warning ~syntax_version ~r_edit_style sigs
-    links_annot ((agent_name, _) as ag_ty) intf counts =
+    links_annot ((agent_name, _) as ag_ty) simple_port_list counter_list =
   let ag_id = Signature.num_of_agent ag_ty sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
@@ -197,22 +197,22 @@ let annotate_dropped_agent ~warning ~syntax_version ~r_edit_style sigs
           let () = ports.(p_id) <- (LKappa.ANY_FREE, pos), LKappa.Erased in
           lannot, pset'
         | [ (LKappa.LNK_SOME, pos_link) ] ->
-          let na, pos = p.Ast.port_name in
+          let port_name, pos = p.Ast.port_name in
           let () =
             warning ~pos (fun f ->
                 Format.fprintf f
                   "breaking a semi-link on site '%s' will induce a side effect"
-                  na)
+                  port_name)
           in
           let () = ports.(p_id) <- (LKappa.LNK_SOME, pos_link), LKappa.Erased in
           lannot, pset'
         | [ (LKappa.LNK_TYPE (dst_p, dst_ty), pos_link) ] ->
-          let na, pos = p.Ast.port_name in
+          let port_name, pos = p.Ast.port_name in
           let () =
             warning ~pos (fun f ->
                 Format.fprintf f
                   "breaking a semi-link on site '%s' will induce a side effect"
-                  na)
+                  port_name)
           in
           let () =
             ports.(p_id) <-
@@ -251,7 +251,7 @@ let annotate_dropped_agent ~warning ~syntax_version ~r_edit_style sigs
             (ExceptionDefn.Malformed_Decl
                ("Several link state for a single site", pos)))
       (links_annot, Mods.IntSet.empty)
-      intf
+      simple_port_list
   in
   let ra =
     {
@@ -262,12 +262,12 @@ let annotate_dropped_agent ~warning ~syntax_version ~r_edit_style sigs
       ra_syntax = Some (Array.copy ports, Array.copy internals);
     }
   in
-  ( Counters_compiler.annotate_dropped_counters sign counts ra arity agent_name
-      None,
+  ( Counters_compiler.annotate_dropped_counters sign counter_list ra arity
+      agent_name None,
     lannot )
 
 let annotate_created_agent ~warning ~syntax_version ~r_edit_style sigs
-    ?contact_map rannot ((agent_name, _) as ag_ty) intf =
+    ?contact_map rannot ((agent_name, _) as ag_ty) simple_port_list =
   let ag_id = Signature.num_of_agent ag_ty sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
@@ -328,7 +328,7 @@ let annotate_created_agent ~warning ~syntax_version ~r_edit_style sigs
           pset', rannot'
         | [ ((LKappa.ANY_FREE | LKappa.LNK_FREE), _) ] | [] -> pset', rannot)
       (Mods.IntSet.empty, rannot)
-      intf
+      simple_port_list
   in
   ( rannot,
     {
@@ -337,17 +337,18 @@ let annotate_created_agent ~warning ~syntax_version ~r_edit_style sigs
       Raw_mixture.a_ints = internals;
     } )
 
-let translate_modification ~warning sigs ?contact_map ag_id p_id ?warn
+let translate_modification ~warning sigs ?contact_map ag_id p_id ?warn_info
     ((lhs_links, rhs_links) as links_annot) = function
   | None -> LKappa.Maintained, links_annot
   | Some x ->
     let () =
-      match warn with
+      match warn_info with
       | None -> ()
-      | Some (na, pos) ->
+      | Some (site_name, pos) ->
         warning ~pos (fun f ->
             Format.fprintf f
-              "breaking a semi-link on site '%s' will induce a side effect" na)
+              "breaking a semi-link on site '%s' will induce a side effect"
+              site_name)
     in
     (match x with
     | None -> LKappa.Freed, links_annot
@@ -359,7 +360,7 @@ let translate_modification ~warning sigs ?contact_map ag_id p_id ?warn
       LKappa.Linked j, (lhs_links, rhs_links'))
 
 let annotate_edit_agent ~warning ~syntax_version ~is_rule sigs ?contact_map
-    ((agent_name, _) as ag_ty) links_annot intf counts =
+    ((agent_name, _) as ag_ty) links_annot simple_port_list counter_list =
   let ag_id = Signature.num_of_agent ag_ty sigs in
   let sign = Signature.get sigs ag_id in
   let arity = Signature.arity sigs ag_id in
@@ -384,22 +385,22 @@ let annotate_edit_agent ~warning ~syntax_version ~is_rule sigs ?contact_map
       match p.Ast.port_link with
       | [ ((LKappa.LNK_SOME, pos) as x) ] ->
         let modif, links_annot' =
-          translate_modification ~warning ~warn:(port_name, pos) sigs
+          translate_modification ~warning ~warn_info:(port_name, pos) sigs
             ?contact_map ag_id p_id links_annot p.Ast.port_link_mod
         in
         let () = ports.(p_id) <- x, modif in
         links_annot'
       | [ (LKappa.LNK_ANY, pos) ] ->
         let modif, links_annot' =
-          translate_modification ~warning ~warn:(port_name, pos) sigs
+          translate_modification ~warning ~warn_info:(port_name, pos) sigs
             ?contact_map ag_id p_id links_annot p.Ast.port_link_mod
         in
         let () = ports.(p_id) <- (LKappa.ANY_FREE, pos), modif in
         links_annot'
       | ([] | [ (LKappa.ANY_FREE, _) ]) when syntax_version = Ast.V3 ->
         let modif, links_annot' =
-          translate_modification ~warning ?warn:None sigs ?contact_map ag_id
-            p_id links_annot p.Ast.port_link_mod
+          translate_modification ~warning ?warn_info:None sigs ?contact_map
+            ag_id p_id links_annot p.Ast.port_link_mod
         in
         let () = ports.(p_id) <- Loc.annot_with_dummy LKappa.LNK_FREE, modif in
         links_annot'
@@ -409,22 +410,22 @@ let annotate_edit_agent ~warning ~syntax_version ~is_rule sigs ?contact_map
           agent_name p.Ast.port_name
       | [ (LKappa.LNK_FREE, _) ] ->
         let modif, links_annot' =
-          translate_modification ~warning ?warn:None sigs ?contact_map ag_id
-            p_id links_annot p.Ast.port_link_mod
+          translate_modification ~warning ?warn_info:None sigs ?contact_map
+            ag_id p_id links_annot p.Ast.port_link_mod
         in
         let () = ports.(p_id) <- Loc.annot_with_dummy LKappa.LNK_FREE, modif in
         links_annot'
       | [ (LKappa.LNK_TYPE (dst_p, dst_ty), pos) ] ->
         let modif, links_annot' =
-          translate_modification ~warning ~warn:(port_name, pos) sigs
+          translate_modification ~warning ~warn_info:(port_name, pos) sigs
             ?contact_map ag_id p_id links_annot p.Ast.port_link_mod
         in
         let () = ports.(p_id) <- build_l_type sigs pos dst_ty dst_p modif in
         links_annot'
       | [ (LKappa.LNK_VALUE (i, ()), pos) ] ->
         let modif, (lhs_links, rhs_links) =
-          translate_modification ~warning ?warn:None sigs ?contact_map ag_id
-            p_id links_annot p.Ast.port_link_mod
+          translate_modification ~warning ?warn_info:None sigs ?contact_map
+            ag_id p_id links_annot p.Ast.port_link_mod
         in
         let va, lhs_links' =
           build_link sigs
@@ -476,7 +477,7 @@ let annotate_edit_agent ~warning ~syntax_version ~is_rule sigs ?contact_map
     links_annot', pset'
   in
   let annoted', _ =
-    List.fold_left scan_port (links_annot, Mods.IntSet.empty) intf
+    List.fold_left scan_port (links_annot, Mods.IntSet.empty) simple_port_list
   in
   let ra =
     {
@@ -487,7 +488,7 @@ let annotate_edit_agent ~warning ~syntax_version ~is_rule sigs ?contact_map
       ra_syntax = Some (Array.copy ports, Array.copy internals);
     }
   in
-  ( Counters_compiler.annotate_edit_counters sigs ag_ty counts ra
+  ( Counters_compiler.annotate_edit_counters sigs ag_ty counter_list ra
       (add_link_contact_map ?contact_map),
     annoted' )
 
@@ -832,7 +833,7 @@ let refer_links_annot ?warning sigs links_annot mix =
         ra.LKappa.ra_ports)
     mix
 
-let separate_sites ls =
+let separate_simple_ports_from_counters ls =
   let a, b =
     List.fold_left
       (fun (ps, cs) -> function
@@ -876,8 +877,8 @@ let annotate_lhs_with_diff_v3 ~warning sigs ?contact_map lhs rhs =
            && Ast.no_more_site_on_right true lag_s rag_s ->
       raise_if_modification_agent lpos lmod;
       raise_if_modification_agent rpos rmod;
-      let lag_p, lag_c = separate_sites lag_s in
-      let rag_p, rag_c = separate_sites rag_s in
+      let lag_p, lag_c = separate_simple_ports_from_counters lag_s in
+      let rag_p, rag_c = separate_simple_ports_from_counters rag_s in
       let ra, links_annot' =
         annotate_agent_with_diff ~warning ~syntax_version sigs ?contact_map
           ag_ty links_annot lag_p rag_p lag_c rag_c
@@ -911,12 +912,15 @@ let annotate_lhs_with_diff_v3 ~warning sigs ?contact_map lhs rhs =
               raise
                 (ExceptionDefn.Malformed_Decl
                    ("Absent agent are KaSim > 3 syntax", pos))
-            | Ast.Present (((_, pos) as na), sites, modif) ->
+            | Ast.Present (((_, pos) as agent_name), sites, modif) ->
               raise_if_modification_agent pos modif;
-              let intf, counts = separate_sites sites in
+              let simple_port_list, counter_list =
+                separate_simple_ports_from_counters sites
+              in
               let ra, lannot' =
                 annotate_dropped_agent ~warning ~syntax_version
-                  ~r_edit_style:false sigs lannot na intf counts
+                  ~r_edit_style:false sigs lannot agent_name simple_port_list
+                  counter_list
               in
               ra :: acc, lannot')
           (acc, fst links_annot)
@@ -929,15 +933,19 @@ let annotate_lhs_with_diff_v3 ~warning sigs ?contact_map lhs rhs =
               raise
                 (ExceptionDefn.Malformed_Decl
                    ("Absent agent are KaSim > 3 syntax", pos))
-            | Ast.Present (((_, pos) as na), sites, modif) ->
+            | Ast.Present (((_, pos) as agent_name), sites, modif) ->
               raise_if_modification_agent pos modif;
-              let intf, counts = separate_sites sites in
+              let simple_port_list, counter_list =
+                separate_simple_ports_from_counters sites
+              in
               let rannot', x' =
                 annotate_created_agent ~warning ~syntax_version
-                  ~r_edit_style:false sigs ?contact_map rannot na intf
+                  ~r_edit_style:false sigs ?contact_map rannot agent_name
+                  simple_port_list
               in
               let x'' =
-                Counters_compiler.annotate_created_counters sigs na counts
+                Counters_compiler.annotate_created_counters sigs agent_name
+                  counter_list
                   (add_link_contact_map ?contact_map)
                   x'
               in
@@ -959,23 +967,29 @@ let annotate_lhs_with_diff_v4 ~warning sigs ?contact_map lhs rhs =
     match lhs, rhs with
     | [], [] -> links_annot, mix, cmix
     | Ast.Absent _ :: lt, Ast.Absent _ :: rt -> aux links_annot mix cmix lt rt
-    | Ast.Present (((_, pos) as ty), sites, lmod) :: lt, Ast.Absent _ :: rt ->
+    | ( Ast.Present (((_, pos) as agent_type), sites, lmod) :: lt,
+        Ast.Absent _ :: rt ) ->
       raise_if_modification_agent pos lmod;
-      let intf, counts = separate_sites sites in
+      let simple_port_list, counter_list =
+        separate_simple_ports_from_counters sites
+      in
       let ra, lannot' =
         annotate_dropped_agent ~warning ~syntax_version ~r_edit_style:false sigs
-          (fst links_annot) ty intf counts
+          (fst links_annot) agent_type simple_port_list counter_list
       in
       aux (lannot', snd links_annot) (ra :: mix) cmix lt rt
-    | Ast.Absent _ :: lt, Ast.Present (((_, pos) as ty), sites, rmod) :: rt ->
+    | ( Ast.Absent _ :: lt,
+        Ast.Present (((_, pos) as agent_type), sites, rmod) :: rt ) ->
       raise_if_modification_agent pos rmod;
-      let intf, counts = separate_sites sites in
+      let simple_port_list, counter_list =
+        separate_simple_ports_from_counters sites
+      in
       let rannot', x' =
         annotate_created_agent ~warning ~syntax_version ~r_edit_style:false sigs
-          ?contact_map (snd links_annot) ty intf
+          ?contact_map (snd links_annot) agent_type simple_port_list
       in
       let x'' =
-        Counters_compiler.annotate_created_counters sigs ty counts
+        Counters_compiler.annotate_created_counters sigs agent_type counter_list
           (add_link_contact_map ?contact_map)
           x'
       in
@@ -988,8 +1002,8 @@ let annotate_lhs_with_diff_v4 ~warning sigs ?contact_map lhs rhs =
       then (
         raise_if_modification_agent lpos lmod;
         raise_if_modification_agent rpos rmod;
-        let lag_p, lag_c = separate_sites lag_s in
-        let rag_p, rag_c = separate_sites rag_s in
+        let lag_p, lag_c = separate_simple_ports_from_counters lag_s in
+        let rag_p, rag_c = separate_simple_ports_from_counters rag_s in
         let ra, links_annot' =
           annotate_agent_with_diff ~warning ~syntax_version sigs ?contact_map
             ag_ty links_annot lag_p rag_p lag_c rag_c
@@ -1042,22 +1056,26 @@ let annotate_edit_mixture ~warning ~syntax_version ~is_rule sigs ?contact_map
     List.fold_left
       (List.fold_left (fun (lannot, acc, news) -> function
          | Ast.Absent _ -> lannot, acc, news
-         | Ast.Present (ty, sites, modif) ->
-           let intf, counts = separate_sites sites in
+         | Ast.Present (agent_type, sites, modif) ->
+           let simple_port_list, counter_list =
+             separate_simple_ports_from_counters sites
+           in
            (match modif with
            | Ast.NoMod ->
              let a, lannot' =
                annotate_edit_agent ~warning ~syntax_version ~is_rule sigs
-                 ?contact_map ty lannot intf counts
+                 ?contact_map agent_type lannot simple_port_list counter_list
              in
              lannot', a :: acc, news
            | Ast.Create ->
              let rannot', x' =
                annotate_created_agent ~warning ~syntax_version
-                 ~r_edit_style:true sigs ?contact_map (snd lannot) ty intf
+                 ~r_edit_style:true sigs ?contact_map (snd lannot) agent_type
+                 simple_port_list
              in
              let x'' =
-               Counters_compiler.annotate_created_counters sigs ty counts
+               Counters_compiler.annotate_created_counters sigs agent_type
+                 counter_list
                  (add_link_contact_map ?contact_map)
                  x'
              in
@@ -1065,7 +1083,8 @@ let annotate_edit_mixture ~warning ~syntax_version ~is_rule sigs ?contact_map
            | Ast.Erase ->
              let ra, lannot' =
                annotate_dropped_agent ~warning ~syntax_version
-                 ~r_edit_style:true sigs (fst lannot) ty intf counts
+                 ~r_edit_style:true sigs (fst lannot) agent_type
+                 simple_port_list counter_list
              in
              (lannot', snd lannot), ra :: acc, news)))
       ( ( (Mods.IntMap.empty, Mods.IntMap.empty),
@@ -1087,14 +1106,17 @@ let annotate_created_mixture ~warning ~syntax_version sigs ?contact_map
            raise
              (ExceptionDefn.Malformed_Decl
                 ("Absent agent cannot occurs in created mixtures", pos))
-         | Ast.Present (ty, sites, _modif) ->
-           let intf, counts = separate_sites sites in
+         | Ast.Present (agent_type, sites, _modif) ->
+           let simple_port_list, counter_list =
+             separate_simple_ports_from_counters sites
+           in
            let rannot', x' =
              annotate_created_agent ~warning ~syntax_version ~r_edit_style:true
-               sigs ?contact_map rannot ty intf
+               sigs ?contact_map rannot agent_type simple_port_list
            in
            let x'' =
-             Counters_compiler.annotate_created_counters sigs ty counts
+             Counters_compiler.annotate_created_counters sigs agent_type
+               counter_list
                (add_link_contact_map ?contact_map)
                x'
            in
@@ -1245,6 +1267,7 @@ let print_expr_of_ast ~warning ~syntax_version sigs tok algs = function
     Primitives.Alg_pexpr
       (alg_expr_of_ast ~warning ~syntax_version sigs tok algs x)
 
+(* Intermediate representation for a rule, used between internal translations *)
 type rule_inter_rep = {
   label_opt: (string * Loc.t) option;
   bidirectional: bool; (* TODO check *)
@@ -1461,7 +1484,7 @@ type acc_function_rules = {
   cleaned_rules: rule_inter_rep list;
 }
 
-(** [name_and_purify] is called in a fold while compiling the rules from Ast.rules into rule_inter_rep *)
+(** [name_and_purify] compiles the rules from Ast.rules into rule_inter_rep, called in a fold *)
 let name_and_purify_rule ~warning ~syntax_version sigs ~contact_map
     (acc : acc_function_rules)
     ((label_opt, (ast_rule, r_pos)) :
@@ -1860,6 +1883,9 @@ type ast_compiled_data = {
      * (syntactic sugar on mixture are not) *)
 }
 
+let inverted_counter_name (name : string) : string =
+  name ^ Signature.inverted_counter_suffix
+
 (** Evaluates to a ast_compil where clte tests have been changed to cgte tests.
  * For this, for each counter where a CLTE test is present, whose values are in [\[a, b\]], initialized at [i] and add a new counter belonging in [a, b] initialized at [a+b-i].
  * Each test [> value] is then translated into a test to the "inverted" counter as [< a+b-value].
@@ -1890,21 +1916,17 @@ let translate_clte_into_cgte (ast_compil : Ast.parsing_compil) =
       [] ast_compil.rules
   in
 
-  let inverted_counter_suffix = "__inverted" in
-  let inverted_counter_name (name : string) : string =
-    name ^ inverted_counter_suffix
-  in
-
   (* Find counters that have CLTE tests, and build list: agent_name, counter_name, sum_bounds_ref list.
    * sum_bounds_ref is then filled when reading the signature and used to specify for inverted counter init value or test value as [sum_bounds_ref - value] *)
   let counters_with_clte_tests : (string * string * int ref) list =
     counter_fold (fun acc agent_name counter ->
         let counter_name = Loc.v counter.counter_name in
         (* Forbid prefix to avoid nonsense in counter definition *)
-        if String.ends_with ~suffix:inverted_counter_suffix counter_name then
+        if Signature.is_inverted_counter counter_name then
           raise
             (ExceptionDefn.Malformed_Decl
-               ( "cannot end counter name by \"" ^ inverted_counter_suffix ^ "\"",
+               ( "cannot end counter name by \""
+                 ^ Signature.inverted_counter_suffix ^ "\"",
                  Loc.get_annot counter.counter_name ));
         (* Return counter name along with matching agent_name *)
         match Option_util.map Loc.v counter.counter_test with
@@ -2227,7 +2249,7 @@ let compil_of_ast ~warning ~debug_mode ~syntax_version ~var_overwrite ast_compil
     else
       ast_compil
   in
-  (* Remove counter variable definition by splitting in several rules *)
+  (* Remove counter equality test with a variable by splitting in one rule per variable value *)
   let ast_compil =
     if has_counters then
       Counters_compiler.split_counter_variables_into_separate_rules ~warning
diff --git a/core/logging/dune b/core/logging/dune
index 501e0308d..eac12b85f 100644
--- a/core/logging/dune
+++ b/core/logging/dune
@@ -10,7 +10,7 @@
    -w
    @a
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_cli
    -open
diff --git a/core/main/dune b/core/main/dune
index 072922ef7..39ce818b0 100644
--- a/core/main/dune
+++ b/core/main/dune
@@ -21,9 +21,9 @@
    -open
    Kappa_version
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/odes/dune b/core/odes/dune
index 43e27d2ef..3e530b623 100644
--- a/core/odes/dune
+++ b/core/odes/dune
@@ -14,9 +14,9 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms
    -open
diff --git a/core/parameters/dune b/core/parameters/dune
index e68cd57f1..a680334ed 100644
--- a/core/parameters/dune
+++ b/core/parameters/dune
@@ -16,7 +16,7 @@
   -open
   Kappa_grammar
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_logging
   -open
diff --git a/core/simulation/dune b/core/simulation/dune
index 6c04c29f1..5ec333eb1 100644
--- a/core/simulation/dune
+++ b/core/simulation/dune
@@ -7,9 +7,9 @@
    -w
    @a
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
-   Kappa_mixtures
+   Kappa_site_graphs
    -open
    Kappa_terms)))
 
diff --git a/core/simulation/generic_rule_interpreter.ml b/core/simulation/generic_rule_interpreter.ml
index a7204a1fd..92a1fafbd 100644
--- a/core/simulation/generic_rule_interpreter.ml
+++ b/core/simulation/generic_rule_interpreter.ml
@@ -49,7 +49,7 @@ module Make (Instances : Instances_sig.S) = struct
   type instance =
     bool
     * int
-    * (Kappa_terms.Matching.t * int list * Kappa_mixtures.Edges.path option)
+    * (Kappa_terms.Matching.t * int list * Kappa_site_graphs.Edges.path option)
       option
 
   type t = {
diff --git a/core/simulation/rule_interpreter.mli b/core/simulation/rule_interpreter.mli
index 2b052d1f5..7570aa09e 100644
--- a/core/simulation/rule_interpreter.mli
+++ b/core/simulation/rule_interpreter.mli
@@ -102,30 +102,30 @@ val get_random_state : t -> Random.State.t
 val obs_from_transformations :
   debug_mode:bool ->
   Kappa_terms.Pattern.Env.t ->
-  Kappa_mixtures.Edges.t ->
+  Kappa_site_graphs.Edges.t ->
   Instantiation.concrete Primitives.Transformation.t list ->
   (Kappa_terms.Pattern.id * Instantiation.concrete) list
-  * Kappa_generic_toolset.Operator.DepSet.t
+  * Kappa_data_structures.Operator.DepSet.t
 
 val print_stats : Format.formatter -> t -> unit
 
 val apply_negative_transformation :
   ?mod_connectivity_store:Roots.mod_ccs_cache ->
   Instances.t ->
-  Agent.t Instantiation.site list * Kappa_mixtures.Edges.t ->
+  Agent.t Instantiation.site list * Kappa_site_graphs.Edges.t ->
   Agent.t Primitives.Transformation.t ->
-  Agent.t Instantiation.site list * Kappa_mixtures.Edges.t
+  Agent.t Instantiation.site list * Kappa_site_graphs.Edges.t
 
 val apply_positive_transformation :
   debug_mode:bool ->
-  Kappa_mixtures.Signature.s ->
+  Kappa_site_graphs.Signature.s ->
   ?mod_connectivity_store:Roots.mod_ccs_cache ->
   Instances.t ->
-  (Kappa_terms.Matching.t * int Kappa_generic_toolset.Mods.IntMap.t)
+  (Kappa_terms.Matching.t * int Kappa_data_structures.Mods.IntMap.t)
   * Agent.t Instantiation.site list
-  * Kappa_mixtures.Edges.t ->
+  * Kappa_site_graphs.Edges.t ->
   Instantiation.abstract Primitives.Transformation.t ->
-  ((Kappa_terms.Matching.t * int Kappa_generic_toolset.Mods.IntMap.t)
+  ((Kappa_terms.Matching.t * int Kappa_data_structures.Mods.IntMap.t)
   * Agent.t Instantiation.site list
-  * Kappa_mixtures.Edges.t)
+  * Kappa_site_graphs.Edges.t)
   * Agent.t Primitives.Transformation.t
diff --git a/core/siteGraphs/dune b/core/siteGraphs/dune
index 6f08d4e32..a4295b1b6 100644
--- a/core/siteGraphs/dune
+++ b/core/siteGraphs/dune
@@ -1,6 +1,6 @@
 (library
- (name kappa_mixtures)
- (libraries kappa_generic_toolset)
+ (name kappa_site_graphs)
+ (libraries kappa_data_structures)
  (public_name kappa-library.mixtures)
  (flags
-  (:standard -w @a-40-42 -open Kappa_generic_toolset)))
+  (:standard -w @a-40-42 -open Kappa_data_structures)))
diff --git a/core/siteGraphs/edges.ml b/core/siteGraphs/edges.ml
index f1d3d0325..94030778e 100644
--- a/core/siteGraphs/edges.ml
+++ b/core/siteGraphs/edges.ml
@@ -567,8 +567,12 @@ let get_connected_component ag graph =
     | Some ccs -> Mods.DynArray.get ccs ag)
 
 (** The snapshot machinery *)
-let one_connected_component sigs ty node graph =
-  let rec build id acc known = function
+let one_connected_component (sigs : Signature.s) (ty : int) (node : int)
+    (graph : tables) : Snapshot.cc_node array =
+  let rec build (id : int)
+      (acc : (int * int * (Edge.t option * int option) list) list)
+      (known : int Mods.IntMap.t) : (int * int) list -> Snapshot.cc_node array =
+    function
     | [] ->
       Tools.array_rev_map_of_list
         (fun (node_id_in_witness, node_type, sites) ->
@@ -636,28 +640,32 @@ let species ~debug_mode sigs root graph =
     let () = Cache.reset (fst tables.caches) in
     specie
 
-let rec aux_build_snapshot raw sigs tables ccs node =
+let rec aux_build_snapshot (raw : bool) (sigs : Signature.s) (tables : tables)
+    (ccs : Snapshot.t) (node : int) : Snapshot.t =
   if node = Mods.DynArray.length tables.sort then (
+    (* We went through all nodes, we return the full snapshot *)
     let () = Cache.reset (fst tables.caches) in
     ccs
   ) else if Cache.test (fst tables.caches) node then
+    (* Already in cache, we continue to the next node *)
     aux_build_snapshot raw sigs tables ccs (succ node)
   else (
     match Mods.DynArray.get tables.sort node with
     | None -> aux_build_snapshot raw sigs tables ccs (succ node)
-    | Some ty ->
+    | Some (ty : int) ->
       let out = one_connected_component sigs ty node tables in
       aux_build_snapshot raw sigs tables
         (Snapshot.increment_in_snapshot ~raw sigs out ccs)
         (succ node)
   )
 
-let build_snapshot ~raw sigs graph =
+let build_snapshot ~(raw : bool) (sigs : Signature.s) (graph : t) : Snapshot.t =
   match graph.tables with
   | None -> assert false
   | Some tables -> aux_build_snapshot raw sigs tables Snapshot.empty 0
 
-let build_user_snapshot ~debug_mode ~raw sigs graph =
+let build_user_snapshot ~(debug_mode : bool) ~(raw : bool) (sigs : Signature.s)
+    (graph : t) : (int * User_graph.connected_component) list =
   Snapshot.export ~debug_mode ~raw sigs (build_snapshot ~raw sigs graph)
 
 let debug_print f graph =
diff --git a/core/siteGraphs/signature.ml b/core/siteGraphs/signature.ml
index 96e4ef077..1230c298a 100644
--- a/core/siteGraphs/signature.ml
+++ b/core/siteGraphs/signature.ml
@@ -214,16 +214,16 @@ let create ~counters_per_agent agent_sigs =
          Some { id = 0; arity = 2; ports = 0, 1 });
   }
 
-let is_counter_agent sigs n_id =
+let is_counter_agent sigs agent_id =
   match sigs.counter_agent_info with
   | None -> false
-  | Some agent_info -> n_id = agent_info.id
+  | Some agent_info -> agent_id = agent_info.id
 
-let ports_if_counter_agent sigs n_id =
+let ports_if_counter_agent sigs agent_id =
   match sigs.counter_agent_info with
   | None -> None
   | Some agent_info ->
-    if n_id = agent_info.id then
+    if agent_id = agent_info.id then
       Some agent_info.ports
     else
       None
@@ -236,6 +236,11 @@ let get_counter_agent_info sigs =
   | None -> failwith "No counter agent"
   | Some counter_agent_info -> counter_agent_info
 
+let inverted_counter_suffix : string = "__inverted"
+
+let is_inverted_counter (counter_name : string) : bool =
+  String.ends_with ~suffix:inverted_counter_suffix counter_name
+
 let print_agent sigs f ag_ty =
   Format.pp_print_string f @@ agent_of_num ag_ty sigs
 
diff --git a/core/siteGraphs/signature.mli b/core/siteGraphs/signature.mli
index da2a872a2..57400ec8a 100644
--- a/core/siteGraphs/signature.mli
+++ b/core/siteGraphs/signature.mli
@@ -88,6 +88,12 @@ type counter_agent_info = { id: int; arity: int; ports: int * int }
 val get_counter_agent_info : s -> counter_agent_info
 (** [counter_agent agent_sigs] *)
 
+val inverted_counter_suffix : string
+(** Suffix added to counter names to make an inverted counter name when needed for a <= test *)
+
+val is_inverted_counter : string -> bool
+(** Tests if a counter is a inverted counter, and should be hidden from the user *)
+
 (** {2 I/O} *)
 
 val print_agent : s -> Format.formatter -> int -> unit
diff --git a/core/siteGraphs/snapshot.ml b/core/siteGraphs/snapshot.ml
index 1a30e628d..61218631b 100644
--- a/core/siteGraphs/snapshot.ml
+++ b/core/siteGraphs/snapshot.ml
@@ -126,13 +126,15 @@ let rec counter_value cc (nid, sid) count =
       ))
     count ag.node_sites
 
-let cc_to_user_cc ~debug_mode ~raw sigs cc =
-  let r = Renaming.empty () in
-  let cc_list, indexes, _ =
+let cc_to_user_cc ?(keep_inverted_counters : bool = false) ~debug_mode ~raw sigs
+    cc =
+  let r : Renaming.t = Renaming.empty () in
+  let (cc_list_without_counters, indexes, _) : cc_node list * Renaming.t * int =
     Tools.array_fold_lefti
       (fun i (acc, indexes, pos) ag ->
-        match Signature.ports_if_counter_agent sigs ag.node_type with
-        | None ->
+        if Signature.is_counter_agent sigs ag.node_type then
+          acc, indexes, pos
+        else (
           let indexes' =
             if i = pos then
               indexes
@@ -146,13 +148,72 @@ let cc_to_user_cc ~debug_mode ~raw sigs cc =
             )
           in
           ag :: acc, indexes', pos + 1
-        | Some _ -> acc, indexes, pos)
+        ))
       ([], r, 0) cc
   in
-  let cc_without_counters = Array.of_list (List.rev cc_list) in
+  let cc_without_counters : cc_node array =
+    Array.of_list (List.rev cc_list_without_counters)
+  in
   [|
     Array.map
       (fun ag ->
+        let node_sites_all : User_graph.cc_site array =
+          Array.mapi
+            (fun id si ->
+              {
+                User_graph.site_name =
+                  Format.asprintf "%a"
+                    (Signature.print_site sigs ag.node_type)
+                    id;
+                User_graph.site_type =
+                  (let port_states =
+                     match si.site_state with
+                     | None -> Some []
+                     | Some s ->
+                       Some
+                         [
+                           Format.asprintf "%a"
+                             (Signature.print_internal_state sigs ag.node_type
+                                id)
+                             s;
+                         ]
+                   in
+                   match si.site_link with
+                   | None ->
+                     User_graph.Port
+                       {
+                         User_graph.port_links = User_graph.LINKS [];
+                         User_graph.port_states;
+                       }
+                   | Some (dn_id, s) ->
+                     let dn_id' =
+                       try Renaming.apply ~debug_mode indexes dn_id
+                       with Renaming.Undefined | Invalid_argument _ -> dn_id
+                     in
+                     if Signature.is_counter_agent sigs cc.(dn_id).node_type
+                     then
+                       User_graph.Counter (counter_value cc (dn_id, s) 0)
+                     else
+                       User_graph.Port
+                         {
+                           User_graph.port_links =
+                             User_graph.LINKS [ (0, dn_id'), s ];
+                           User_graph.port_states;
+                         });
+              })
+            ag.node_sites
+        in
+        let node_sites : User_graph.cc_site array =
+          if keep_inverted_counters then
+            node_sites_all
+          else
+            (* Remove inverted counters from user snapshot *)
+            node_sites_all |> Array.to_list
+            |> List.filter (fun (site : User_graph.cc_site) : bool ->
+                   not(Signature.is_inverted_counter site.site_name))
+            |> Array.of_list
+        in
+
         Some
           {
             User_graph.node_id =
@@ -162,55 +223,7 @@ let cc_to_user_cc ~debug_mode ~raw sigs cc =
                  None);
             User_graph.node_type =
               Format.asprintf "%a" (Signature.print_agent sigs) ag.node_type;
-            User_graph.node_sites =
-              Array.mapi
-                (fun id si ->
-                  {
-                    User_graph.site_name =
-                      Format.asprintf "%a"
-                        (Signature.print_site sigs ag.node_type)
-                        id;
-                    User_graph.site_type =
-                      (let port_states =
-                         match si.site_state with
-                         | None -> Some []
-                         | Some s ->
-                           Some
-                             [
-                               Format.asprintf "%a"
-                                 (Signature.print_internal_state sigs
-                                    ag.node_type id)
-                                 s;
-                             ]
-                       in
-                       match si.site_link with
-                       | None ->
-                         User_graph.Port
-                           {
-                             User_graph.port_links = User_graph.LINKS [];
-                             User_graph.port_states;
-                           }
-                       | Some (dn_id, s) ->
-                         let dn_id' =
-                           try Renaming.apply ~debug_mode indexes dn_id
-                           with Renaming.Undefined | Invalid_argument _ ->
-                             dn_id
-                         in
-                         (match
-                            Signature.ports_if_counter_agent sigs
-                              cc.(dn_id).node_type
-                          with
-                         | None ->
-                           User_graph.Port
-                             {
-                               User_graph.port_links =
-                                 User_graph.LINKS [ (0, dn_id'), s ];
-                               User_graph.port_states;
-                             }
-                         | Some _ ->
-                           User_graph.Counter (counter_value cc (dn_id, s) 0)));
-                  })
-                ag.node_sites;
+            User_graph.node_sites;
           })
       cc_without_counters;
   |]
diff --git a/core/siteGraphs/snapshot.mli b/core/siteGraphs/snapshot.mli
index 71f9c69cf..077a1bf28 100644
--- a/core/siteGraphs/snapshot.mli
+++ b/core/siteGraphs/snapshot.mli
@@ -21,6 +21,7 @@ type connected_component = cc_node array
 type t
 
 val cc_to_user_cc :
+  ?keep_inverted_counters:bool ->
   debug_mode:bool ->
   raw:bool ->
   Signature.s ->
diff --git a/core/symmetries/dune b/core/symmetries/dune
index 0df77fed1..3ff48e4a6 100644
--- a/core/symmetries/dune
+++ b/core/symmetries/dune
@@ -8,11 +8,11 @@
   -open
   Kappa_terms
   -open
-  Kappa_mixtures
+  Kappa_site_graphs
   -open
   Kappa_parameters
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_logging
   -open
diff --git a/core/term/contact_map.ml b/core/term/contact_map.ml
index bf6fa6db0..125ba0b52 100644
--- a/core/term/contact_map.ml
+++ b/core/term/contact_map.ml
@@ -67,7 +67,7 @@ let of_yojson (a : Yojson.Basic.t) =
 let print_kappa ~noCounters sigs f c =
   Format.fprintf f "@[<v>%a@]"
     (Pp.array Pp.space (fun ag f intf ->
-         if Signature.ports_if_counter_agent sigs ag = None || noCounters then
+         if (not (Signature.is_counter_agent sigs ag)) || noCounters then
            Format.fprintf f "@[<hv 2>%%agent:@ %a(@[%a@])@]"
              (Signature.print_agent sigs)
              ag
diff --git a/core/term/dune b/core/term/dune
index d33e95dcf..ea63b6d04 100644
--- a/core/term/dune
+++ b/core/term/dune
@@ -1,6 +1,6 @@
 (library
  (name kappa_terms)
- (libraries kappa_mixtures)
+ (libraries kappa_site_graphs)
  (public_name kappa-library.terms)
  (flags
-  (:standard -w @a -open Kappa_generic_toolset -open Kappa_mixtures)))
+  (:standard -w @a -open Kappa_data_structures -open Kappa_site_graphs)))
diff --git a/gui/dune b/gui/dune
index af68c8206..1747a7b83 100644
--- a/gui/dune
+++ b/gui/dune
@@ -111,7 +111,7 @@
   -open
   Kappa_json_api
   -open
-  Kappa_generic_toolset
+  Kappa_data_structures
   -open
   Kappa_terms
   -open
diff --git a/webapp/dune b/webapp/dune
index 03ad6a6b8..1e438e2ba 100644
--- a/webapp/dune
+++ b/webapp/dune
@@ -13,7 +13,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_version
    -open


Test patch:
diff --git a/core/KaSa_rep/sanity_test/dune b/core/KaSa_rep/sanity_test/dune
index c1cb46f0d..d22a6526c 100644
--- a/core/KaSa_rep/sanity_test/dune
+++ b/core/KaSa_rep/sanity_test/dune
@@ -4,7 +4,7 @@
  (flags
   (:standard
    -open
-   Kappa_generic_toolset
+   Kappa_data_structures
    -open
    Kappa_kasa_kastor_toolset
    -open
diff --git a/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref b/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
index 7aa887165..28429451b 100644
--- a/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
+++ b/tests/integration/compiler/counters_smaller_than_default/output/error.log.ref
@@ -1,5 +1,5 @@
 _____(1)
-A(c{=0} c__inverted{=0})+
+A(c{=0} c__inverted{=7})+
 _____(1)
 A(c{>=0/+=1} c__inverted{>=1/+=-1})
 _____(1)
@@ -11,7 +11,7 @@ Environment:
   %agent: A(c{=0/+=7} c__inverted{=0/+=7})
   
   %plot: [T]
-  A(c{=0} c__inverted{=0})+ @ 1
+  A(c{=0} c__inverted{=7})+ @ 1
   A(c{>=0/+=1} c__inverted{>=1/+=-1}) @ 1
   
   /*0*/%mod: (|A(c__inverted{=8})| = 1) do $PRINTF ""; $PRINTF "Counter c__inverted of agent A reached maximum"; $STOP "counter_perturbation.ka"; repeat [false]
@@ -22,7 +22,21 @@ Environment:
          __counter_agent/*ν 1*/.a = A/*ν 0*/.c,
          __counter_agent/*ν 1*/.b = ⊥, __counter_agent/*ν 2*/,
          __counter_agent/*ν 2*/.a = A/*ν 0*/.c__inverted,
-         __counter_agent/*ν 2*/.b = ⊥
+         __counter_agent/*ν 3*/,
+         __counter_agent/*ν 3*/.a = __counter_agent/*ν 2*/.b,
+         __counter_agent/*ν 4*/,
+         __counter_agent/*ν 4*/.a = __counter_agent/*ν 3*/.b,
+         __counter_agent/*ν 5*/,
+         __counter_agent/*ν 5*/.a = __counter_agent/*ν 4*/.b,
+         __counter_agent/*ν 6*/,
+         __counter_agent/*ν 6*/.a = __counter_agent/*ν 5*/.b,
+         __counter_agent/*ν 7*/,
+         __counter_agent/*ν 7*/.a = __counter_agent/*ν 6*/.b,
+         __counter_agent/*ν 8*/,
+         __counter_agent/*ν 8*/.a = __counter_agent/*ν 7*/.b,
+         __counter_agent/*ν 9*/,
+         __counter_agent/*ν 9*/.a = __counter_agent/*ν 8*/.b,
+         __counter_agent/*ν 9*/.b = ⊥
       @1
     1: (ast: 2) 0: /*cc1*/ A/*1*/(c{=0} c__inverted{=1})
       -- __counter_agent/*4*//*0*/.a = A/*1*//*0*/.c,
diff --git a/tests/integration/simulation/counters_create/output/error.log.ref b/tests/integration/simulation/counters_create/output/error.log.ref
index 55a24aebb..860ada96a 100644
--- a/tests/integration/simulation/counters_create/output/error.log.ref
+++ b/tests/integration/simulation/counters_create/output/error.log.ref
@@ -9,7 +9,7 @@ Environment:
   %plot: [T]
   %plot: B
   
-  'tick' A(c[2] c__inverted[3])+, __counter_agent(a[2] b[.])+, __counter_agent(a[3] b[.])+ @ 1
+  'tick' A(c[2] c__inverted[3])+, __counter_agent(a[2] b[.])+, __counter_agent(a[3] b[4])+, __counter_agent(a[4] b[5])+, __counter_agent(a[5] b[6])+, __counter_agent(a[6] b[7])+, __counter_agent(a[7] b[8])+, __counter_agent(a[8] b[9])+, __counter_agent(a[9] b[10])+, __counter_agent(a[10] b[11])+, __counter_agent(a[11] b[12])+, __counter_agent(a[12] b[13])+, __counter_agent(a[13] b[.])+ @ 1
   A(c[1/2] c__inverted[3/4]), __counter_agent(a[1/1]), __counter_agent(a[3] b[4])-, __counter_agent(a[4/4]), B()+, __counter_agent(a[2] b[1])+ @ 1
   
   /*0*/%mod: (|A(c__inverted[1]), __counter_agent(a[1] b[2]), __counter_agent(a[2] b[3]), __counter_agent(a[3] b[4]), __counter_agent(a[4] b[5]), __counter_agent(a[5] b[6]), __counter_agent(a[6] b[7]), __counter_agent(a[7] b[8]), __counter_agent(a[8] b[9]), __counter_agent(a[9] b[10]), __counter_agent(a[10] b[11]), __counter_agent(a[11] b[12]), __counter_agent(a[12])| = 1) do $PRINTF ""; $PRINTF "Counter c__inverted of agent A reached maximum"; $STOP "counter_perturbation.ka"; repeat [false]
@@ -20,7 +20,27 @@ Environment:
          __counter_agent/*ν 1*/.a = A/*ν 0*/.c,
          __counter_agent/*ν 1*/.b = ⊥, __counter_agent/*ν 2*/,
          __counter_agent/*ν 2*/.a = A/*ν 0*/.c__inverted,
-         __counter_agent/*ν 2*/.b = ⊥
+         __counter_agent/*ν 3*/,
+         __counter_agent/*ν 3*/.a = __counter_agent/*ν 2*/.b,
+         __counter_agent/*ν 4*/,
+         __counter_agent/*ν 4*/.a = __counter_agent/*ν 3*/.b,
+         __counter_agent/*ν 5*/,
+         __counter_agent/*ν 5*/.a = __counter_agent/*ν 4*/.b,
+         __counter_agent/*ν 6*/,
+         __counter_agent/*ν 6*/.a = __counter_agent/*ν 5*/.b,
+         __counter_agent/*ν 7*/,
+         __counter_agent/*ν 7*/.a = __counter_agent/*ν 6*/.b,
+         __counter_agent/*ν 8*/,
+         __counter_agent/*ν 8*/.a = __counter_agent/*ν 7*/.b,
+         __counter_agent/*ν 9*/,
+         __counter_agent/*ν 9*/.a = __counter_agent/*ν 8*/.b,
+         __counter_agent/*ν 10*/,
+         __counter_agent/*ν 10*/.a = __counter_agent/*ν 9*/.b,
+         __counter_agent/*ν 11*/,
+         __counter_agent/*ν 11*/.a = __counter_agent/*ν 10*/.b,
+         __counter_agent/*ν 12*/,
+         __counter_agent/*ν 12*/.a = __counter_agent/*ν 11*/.b,
+         __counter_agent/*ν 12*/.b = ⊥
       @1
     1: (ast: 2)
       0: /*cc2*/ A/*2*/(c[1] c__inverted[2]),
@@ -63,5 +83,5 @@ Domain:
         3
        -2(c[a.!__counter_agent-5])->() 2)
 Intial graph;
-  %init: 1 A(c{=0} c__inverted{=10})
+  %init: 1 A(c{=0})
   
diff --git a/tests/integration/simulation/counters_create/output/inputs.ka.ref b/tests/integration/simulation/counters_create/output/inputs.ka.ref
index 2d3c3c95c..77f12712a 100644
--- a/tests/integration/simulation/counters_create/output/inputs.ka.ref
+++ b/tests/integration/simulation/counters_create/output/inputs.ka.ref
@@ -14,7 +14,7 @@
 %plot: [T]
 %plot: B
 
-'tick' A(c{=0} c__inverted{=0})+ @ 1
+'tick' A(c{=0} c__inverted{=10})+ @ 1
 A(c{>=0/+=1} c__inverted{>=1/+=-1}), B()+ @ 1
 
 /*0*/%mod: (|A(c__inverted{=11})| = 1) do $PRINTF ""; $PRINTF "Counter c__inverted of agent A reached maximum"; $STOP "counter_perturbation.ka"; repeat [false]