text stringlengths 0 601k |
|---|
let do_we_prompt_reactions compil = compil . show_reactions |
let print_chemical_species ? compil f = Format . fprintf f " [ @< h >% a ] " @ ( Kade_backend . Pattern . print_cc ~ noCounters ( : match compil with None -> false | Some c -> c . debugMode ) ~ full_species : true ? sigs ( : Option_util . map Model . signatures ( environment_opt compil ) ) ? cc_id : None ~ symbol_table... |
let print_token ? compil fmt k = Format . fprintf fmt " % a " ( Model . print_token ? env ( : environment_opt compil ) ) k |
let nbr_automorphisms_in_chemical_species ~ debugMode x = List . length ( Pattern . automorphisms ~ debugMode x ) |
let print_connected_component ? compil = Kade_backend . Pattern . print ~ noCounters ( : match compil with None -> false | Some c -> c . debugMode ) ? domain ( : domain_opt compil ) ~ symbol_table ( : symbol_table_opt compil ) ~ with_id : false |
let canonic_form x = x |
let connected_components_of_mixture_sigs ~ debugMode sigs cache contact_map_int e = let ( cache , acc ) = Pattern_decompiler . patterns_of_mixture ~ debugMode contact_map_int sigs cache e in cache , acc |
let connected_components_of_mixture compil cache e = let cc_cache = get_cc_cache cache in let contact_map = contact_map compil in let sigs = Pattern . Env . signatures ( domain compil ) in let cc_cache , acc = Pattern_decompiler . patterns_of_mixture ~ debugMode : compil . debugMode contact_map sigs cc_cache e in set_c... |
let lift_embedding x = Option_util . unsome Matching . empty ( Matching . add_cc Matching . empty 0 x ) |
let find_all_embeddings compil cc = let tr = Primitives . fully_specified_pattern_to_positive_transformations cc in let env = environment compil in let l = Evaluator . find_all_embeddings ~ debugMode : true env tr in Tools . remove_double_elements l |
let add_fully_specified_to_graph ~ debugMode sigs graph cc = let e , g = Pattern . fold_by_type ( fun ~ pos ~ agent_type intf ( emb , g ) -> let a , g ' = Edges . add_agent sigs agent_type g in let ag = ( a , agent_type ) in let emb ' = Mods . IntMap . add pos ag emb in emb ' , Tools . array_fold_lefti ( fun site acc (... |
let find_embeddings compil = Pattern . embeddings_to_fully_specified ~ debugMode : compil . debugMode ( domain compil ) |
let f ~ debugMode ren acc ( i , _cc ) em = List_util . map_flatten ( fun m -> List_util . map_option ( fun r -> Matching . add_cc m i ( Renaming . compose ~ debugMode true r ren ) ) em ) acc |
let compose_embeddings_unary_binary compil p emb_list x = let mix , ren = add_fully_specified_to_graph ~ debugMode : compil . debugMode ( Model . signatures compil . environment ) ( Edges . empty ~ with_connected_components : false ) x in let cc_list = Tools . array_fold_lefti ( fun i acc cc -> ( i , cc ) :: acc ) [ ] ... |
let disjoint_union_sigs ~ debugMode sigs l = let pat = Tools . array_map_of_list ( fun ( x , _ , _ ) -> x ) l in let _ , em , mix = List . fold_left ( fun ( i , em , mix ) ( _ , r , cc ) -> let i = pred i in let ( mix ' , r ' ) = add_fully_specified_to_graph ~ debugMode sigs mix cc in let r ' ' = Renaming . compose ~ d... |
let disjoint_union compil l = let sigs = Model . signatures ( compil . environment ) in disjoint_union_sigs ~ debugMode : compil . debugMode sigs l |
type rule_id_with_mode = rule_id * arity * direction |
let lhs _compil _rule_id r = r . Primitives . connected_components |
let is_zero expr = match expr with | Alg_expr . CONST a , _ -> Nbr . is_zero a | ( ( Alg_expr . BIN_ALG_OP ( _ , _ , _ ) | Alg_expr . UN_ALG_OP ( _ , _ ) | Alg_expr . IF ( _ , _ , _ ) | Alg_expr . DIFF_TOKEN _ | Alg_expr . DIFF_KAPPA_INSTANCE _ | Alg_expr . STATE_ALG_OP _ | Alg_expr . ALG_VAR _ | Alg_expr . KAPPA_INSTA... |
let add_not_none_not_zero x y list = match y with | None -> list | Some x when is_zero ( fst x ) -> list | Some _ -> x :: list |
let add_not_zero x y list = if is_zero y then list else x :: list |
let mode_of_rule _compil _rule = Rule_modes . Direct |
let n_cc cache compil rule = let id = rule . Primitives . syntactic_rule in let rule_cache = get_rule_cache cache in let lkappa_rule = Model . get_ast_rule compil . environment id in let rule_cache , arity = LKappa_auto . n_cc rule_cache lkappa_rule in let cache = set_rule_cache rule_cache cache in cache , arity |
let n_cc cache compil rule = hash_rule_weight ( fun cache rule -> let id = rule . Primitives . syntactic_rule in Mods . DynArray . get cache . n_cc id ) ( fun cache rule n -> let id = rule . Primitives . syntactic_rule in let ( ) = Mods . DynArray . set cache . n_cc id ( Some n ) in cache ) n_cc cache compil rule |
let valid_modes cache compil rule = let id = rule . Primitives . syntactic_rule in let cache , arity = n_cc cache compil rule in let arity ' = Array . length rule . Primitives . connected_components in let mode = mode_of_rule compil rule in let ( ) = assert ( arity ' <= arity ) in let mode_list = if arity = arity ' the... |
let rate _compil rule ( _ , arity , _ ) = match arity with | Rule_modes . Usual -> Some rule . Primitives . rate | ( Rule_modes . Unary | Rule_modes . Unary_refinement ) -> Option_util . map fst rule . Primitives . unary_rate |
let token_vector a = a . Primitives . delta_tokens |
let print_rule_id log = Format . fprintf log " % i " |
let print_rule ? compil = match compil with | None -> Kade_backend . Kappa_printer . elementary_rule ~ noCounters : true ? env : None ? symbol_table : None | Some compil -> Kade_backend . Kappa_printer . decompiled_rule ~ noCounters : compil . debugMode ~ full : true ( environment compil ) ~ symbol_table ( : symbol_tab... |
let print_rule_name ? compil f r = let env = environment_opt compil in let id = r . Primitives . syntactic_rule in Kade_backend . Model . print_ast_rule ~ noCounters ( : match compil with None -> false | Some c -> c . debugMode ) ? env ~ symbol_table ( : symbol_table_opt compil ) f id |
let string_of_var_id ? compil ? init_mode logger r = let f logger r = match Loggers . get_encoding_format logger with | Loggers . Mathematica | Loggers . Maple -> " var " ( ^ string_of_int r ) ( ^ match init_mode with Some true -> " " | Some _ | None -> " ( t ) " ) | Loggers . Octave | Loggers . Matlab -> " var ( " ( ^... |
let string_of_var_id_jac ? compil r dt = let _ = compil in " jacvar ( " ( ^ string_of_int r ) " , " ( ^^ string_of_int dt ) " ) " ^ |
let rate_name compil rule rule_id = let ( _kade_id , arity , direction ) = rule_id in let arity_tag = match arity with | Rule_modes . Usual -> " " | ( Rule_modes . Unary | Rule_modes . Unary_refinement ) -> " ( unary context ) " in let direction_tag = match direction with | Rule_modes . Direct -> " " | Rule_modes . Op ... |
let apply_sigs ~ debugMode env rule inj_nodes mix = let concrete_removed = List . map ( Primitives . Transformation . concretize ~ debugMode ( inj_nodes , Mods . IntMap . empty ) ) rule . Primitives . removed in let dummy_instances = Instances . empty env in let ( side_effects , edges_after_neg ) = List . fold_left ( R... |
let apply compil rule inj_nodes mix = apply_sigs ~ debugMode : compil . debugMode compil . environment rule inj_nodes mix |
let get_rules compil = Model . fold_rules ( fun _ acc r -> r :: acc ) [ ] ( environment compil ) |
let get_variables compil = Model . get_algs ( environment compil ) |
let get_obs compil = Array . to_list ( Model . map_observables ( fun r -> r ) ( environment compil ) ) |
let remove_escape_char = String . map ( function ' ' ' \ -> ' ' | | x -> x ) |
let get_obs_titles compil = let env = environment compil in Array . to_list @@ Model . map_observables ( fun x -> remove_escape_char ( Format . asprintf " % a " ( Kade_backend . Kappa_printer . alg_expr ~ noCounters : compil . debugMode ~ env ~ symbol_table ( : symbol_table compil ) ) x ) ) env |
let get_preprocessed_ast cli_args = let warning ~ pos msg = Data . print_warning ~ pos Format . err_formatter msg in Cli_init . get_preprocessed_ast_from_cli_args ~ warning ~ debugMode : false cli_args |
let to_preprocessed_ast x = x |
let get_ast cli_args = Cli_init . get_ast_from_cli_args cli_args |
let to_ast x = x |
let preprocess cli_args ast = let warning ~ pos msg = Data . print_warning ~ pos Format . err_formatter msg in Cli_init . preprocess ~ warning ~ debugMode : false cli_args ast |
let saturate_domain_with_symmetric_patterns ~ debugMode bwd_bisim_info env = let contact_map = Model . contact_map env in let preenv ' = Model . fold_mixture_in_expr ( fun domain ccs -> LKappa_group_action . saturate_domain_with_symmetric_patterns ~ debugMode ~ compileModeOn : false env bwd_bisim_info ccs domain ) ( Pa... |
let get_compil ~ debugMode ~ dotnet ? bwd_bisim ~ rule_rate_convention ? reaction_rate_convention ~ show_reactions ~ count ~ internal_meaning ~ compute_jacobian cli_args preprocessed_ast = let warning ~ pos msg = Data . print_warning ~ pos Format . err_formatter msg in let ( _ , env , contact_map , _ , _ , _ , _ , init... |
let empty_cc_cache compil = Pattern . PreEnv . of_env ( Model . domain compil . environment ) |
let empty_lkappa_cache ( ) = LKappa_auto . init_cache ( ) |
let empty_sym_cache ( ) = Symmetries . empty_cache ( ) |
let empty_seen_cache ( ) = Mods . DynArray . create 1 false |
let empty_rule_weight ( ) = Mods . DynArray . create 1 None |
let empty_cache compil = { cc_cache = empty_cc_cache compil ; rule_cache = empty_lkappa_cache ( ) ; representative_cache = empty_sym_cache ( ) ; seen_pattern = empty_seen_cache ( ) ; seen_rule = empty_seen_cache ( ) ; seen_species = empty_seen_cache ( ) ; n_cc = empty_rule_weight ( ) ; correcting_coef = empty_rule_weig... |
let mixture_of_init compil c = let _ , emb , m = disjoint_union compil [ ] in let m = apply compil c emb m in m |
let mixture_of_init_sigs ~ debugMode env c = let _ , emb , m = disjoint_union_sigs ~ debugMode ( Model . signatures env ) [ ] in let m = apply_sigs ~ debugMode env c emb m in m |
let species_of_initial_state_env ~ debugMode env contact_map_int cache list = let sigs = Model . signatures env in let cache , list = List . fold_left ( fun ( cache , list ) ( _ , r ) -> let b = mixture_of_init_sigs ~ debugMode env r in let cache ' , acc = connected_components_of_mixture_sigs ~ debugMode sigs cache con... |
let species_of_initial_state compil cache list = let cc_cache , list = species_of_initial_state_env ~ debugMode : compil . debugMode compil . environment ( contact_map compil ) ( get_cc_cache cache ) list in set_cc_cache cc_cache cache , list |
let nb_tokens compil = Model . nb_tokens ( environment compil ) |
let divide_rule_rate_by cache compil rule = match compil . rule_rate_convention with | Remanent_parameters_sig . Common -> assert false | Remanent_parameters_sig . No_correction -> cache , 1 | Remanent_parameters_sig . Biochemist | Remanent_parameters_sig . Divide_by_nbr_of_autos_in_lhs -> let rule_id = rule . Primitiv... |
let divide_rule_rate_by cache compil rule = hash_rule_weight ( fun cache rule -> let rule_id = rule . Primitives . syntactic_rule in Mods . DynArray . get cache . correcting_coef rule_id ) ( fun cache rule n -> let rule_id = rule . Primitives . syntactic_rule in let ( ) = Mods . DynArray . set cache . correcting_coef r... |
let detect_symmetries parameters compil cache chemical_species contact_map = let rule_cache = get_rule_cache cache in let rule_cache , symmetries = Symmetries . detect_symmetries parameters compil . environment rule_cache compil . rule_rate_convention chemical_species ( get_rules compil ) contact_map in set_rule_cache ... |
let print_symmetries parameters compil symmetries = let env = compil . environment in Symmetries . print_symmetries parameters env symmetries |
let valid_mixture compil cc_cache ? max_size mixture = match max_size with | None -> cc_cache , true | Some n -> let cc_cache , cc_list = connected_components_of_mixture compil cc_cache mixture in cc_cache , List . for_all ( fun cc -> Pattern . size_of_cc cc <= n ) cc_list |
let init_bwd_bisim_info red = red , Mods . DynArray . create 1 false , ref ( LKappa_auto . init_cache ( ) ) |
module type ObsMap = sig type ' a t val empty : ' a -> ' a t val add : connected_component -> ' a -> ' a list t -> ' a list t val get : connected_component -> ' a list t -> ' a list val reset : connected_component -> ' a list t -> ' a list t end |
module ObsMap = ( struct type ' a t = ' a Pattern . ObsMap . t let empty a = Pattern . ObsMap . dummy a let get cc map = Pattern . ObsMap . get map cc let add cc data map = let old = get cc map in let ( ) = Pattern . ObsMap . set map cc ( data :: old ) in map let reset cc map = let ( ) = Pattern . ObsMap . set map cc [... |
module type Interface = sig type ast type preprocessed_ast type compil type cache type mixture type chemical_species type canonic_species type pattern type connected_component type rule type init = ( ( connected_component array list , int ) Alg_expr . e * rule ) list val debug_mode : compil -> bool val do_we_allow_empt... |
type error = Undefined_global of string | Unavailable_primitive of string | Wrong_vm of string | Uninitialized_global of string |
module Num_tbl ( M : Map . S ) = struct type t = { cnt : int ; tbl : int M . t ; } let empty = { cnt = 0 ; tbl = M . empty } let find nt key = M . find key nt . tbl let enter nt key = let n = ! nt . cnt in nt := { cnt = n + 1 ; tbl = M . add key n ! nt . tbl } ; n let incr nt = let n = ! nt . cnt in nt := { cnt = n + 1... |
let global_table = ref GlobalMap . empty |
let is_global_defined id = Ident . Map . mem id ( ! global_table ) . tbl |
let slot_for_getglobal id = try GlobalMap . find ! global_table id with Not_found -> raise ( Error ( Undefined_global ( Ident . name id ) ) ) |
let slot_for_setglobal id = GlobalMap . enter global_table id |
let slot_for_literal cst = let n = GlobalMap . incr global_table in literal_table := ( n , cst ) :: ! literal_table ; n |
let c_prim_table = ref PrimMap . empty |
let set_prim_table name = ignore ( PrimMap . enter c_prim_table name ) |
let of_prim name = try PrimMap . find ! c_prim_table name with Not_found -> if ! Clflags . custom_runtime || Config . host <> Config . target || ! Clflags . no_check_prims then PrimMap . enter c_prim_table name else begin let symb = try Dll . find_primitive name with Not_found -> raise ( Error ( Unavailable_primitive n... |
let require_primitive name = if name . [ 0 ] <> ' ' % then ignore ( of_prim name ) |
let all_primitives ( ) = let prim = Array . make ! c_prim_table . cnt " " in String . Map . iter ( fun name number -> prim . ( number ) <- name ) ! c_prim_table . tbl ; prim |
let data_primitive_names ( ) = let prim = all_primitives ( ) in let b = Buffer . create 512 in for i = 0 to Array . length prim - 1 do Buffer . add_string b prim . ( i ) ; Buffer . add_char b ' \ 000 ' done ; Buffer . contents b |
let output_primitive_names outchan = output_string outchan ( data_primitive_names ( ) ) |
let output_primitive_table outchan = let prim = all_primitives ( ) in for i = 0 to Array . length prim - 1 do fprintf outchan " extern value % s ( ) ; \ n " prim . ( i ) done ; fprintf outchan " typedef value 0 } ; \ n " |
let init ( ) = Array . iteri ( fun i name -> let id = try List . assoc name Predef . builtin_values with Not_found -> fatal_error " Symtable . init " in let c = slot_for_setglobal id in let cst = Const_block ( Obj . object_tag , [ Const_base ( Const_string ( name , None ) ) ; Const_base ( Const_int ( - i - 1 ) ) ] ) in... |
let patch_int buff pos n = LongString . set buff pos ( Char . unsafe_chr n ) ; LongString . set buff ( pos + 1 ) ( Char . unsafe_chr ( n asr 8 ) ) ; LongString . set buff ( pos + 2 ) ( Char . unsafe_chr ( n asr 16 ) ) ; LongString . set buff ( pos + 3 ) ( Char . unsafe_chr ( n asr 24 ) ) |
let patch_object buff patchlist = List . iter ( function ( Reloc_literal sc , pos ) -> patch_int buff pos ( slot_for_literal sc ) | ( Reloc_getglobal id , pos ) -> patch_int buff pos ( slot_for_getglobal id ) | ( Reloc_setglobal id , pos ) -> patch_int buff pos ( slot_for_setglobal id ) | ( Reloc_primitive name , pos )... |
let rec transl_const = function Const_base ( Const_int i ) -> Obj . repr i | Const_base ( Const_char c ) -> Obj . repr c | Const_base ( Const_string ( s , _ ) ) -> Obj . repr s | Const_base ( Const_float f ) -> Obj . repr ( float_of_string f ) | Const_base ( Const_int32 i ) -> Obj . repr i | Const_base ( Const_int64 i ... |
let initial_global_table ( ) = let glob = Array . make ! global_table . cnt ( Obj . repr 0 ) in List . iter ( fun ( slot , cst ) -> glob . ( slot ) <- transl_const cst ) ! literal_table ; literal_table := [ ] ; glob |
let output_global_map oc = output_value oc ! global_table |
let data_global_map ( ) = Obj . repr ! global_table |
let update_global_table ( ) = let ng = ! global_table . cnt in if ng > Array . length ( Meta . global_data ( ) ) then Meta . realloc_global_data ng ; let glob = Meta . global_data ( ) in List . iter ( fun ( slot , cst ) -> glob . ( slot ) <- transl_const cst ) ! literal_table ; literal_table := [ ] |
type section_reader = { read_string : string -> string ; read_struct : string -> Obj . t ; close_reader : unit -> unit } |
let read_sections ( ) = try let sections = Meta . get_section_table ( ) in { read_string = ( fun name -> ( Obj . magic ( List . assoc name sections ) : string ) ) ; read_struct = ( fun name -> List . assoc name sections ) ; close_reader = ( fun ( ) -> ( ) ) } with Not_found -> let ic = open_in_bin Sys . executable_name... |
let init_toplevel ( ) = try let sect = read_sections ( ) in global_table := ( Obj . magic ( sect . read_struct " SYMB " ) : GlobalMap . t ) ; let prims = sect . read_string " PRIM " in c_prim_table := PrimMap . empty ; let pos = ref 0 in while ! pos < String . length prims do let i = String . index_from prims ! pos ' \... |
let get_global_position id = slot_for_getglobal id |
let get_global_value id = ( Meta . global_data ( ) ) . ( slot_for_getglobal id ) |
let assign_global_value id v = ( Meta . global_data ( ) ) . ( slot_for_getglobal id ) <- v |
let defined_globals patchlist = List . fold_left ( fun accu rel -> match rel with | ( Reloc_setglobal id , _pos ) -> id :: accu | _ -> accu ) [ ] patchlist |
let required_globals patchlist = List . fold_left ( fun accu rel -> match rel with | ( Reloc_getglobal id , _pos ) -> id :: accu | _ -> accu ) [ ] patchlist |
let check_global_initialized patchlist = let defined_globals = defined_globals patchlist in let check_reference = function ( Reloc_getglobal id , _pos ) -> if not ( List . mem id defined_globals ) && Obj . is_int ( get_global_value id ) then raise ( Error ( Uninitialized_global ( Ident . name id ) ) ) | _ -> ( ) in Lis... |
let current_state ( ) = ! global_table |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.