Commit 04391bed authored by Sébastien Gamblin's avatar Sébastien Gamblin
Browse files

Some calculation optimizations

parent 842a6535
Loading
Loading
Loading
Loading
+6 −2
Changes for hanabi_launcher.py: 6 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ from __future__ import print_function

import os, sys

p = os.path.abspath('.')
p = os.path.abspath('scripts')
sys.path.insert(1, p)

#<-- End of the trick
@@ -123,6 +123,7 @@ def run_product(ex, logtime, select=False, display=False):

mc_timeout = []


def model_checking(ex, logtime):

    global args, mc_timeout
@@ -139,7 +140,7 @@ def model_checking(ex, logtime):
    time_f = time.time()

    for i, (fname, f) in enumerate(ex.get_formulas_to_check(proba=args.probability)):
        if not i in args.formulas:
        if i not in args.formulas:
            try:
                sub_mc(i, fname, f)
            except KeyboardInterrupt:
@@ -151,9 +152,12 @@ def model_checking(ex, logtime):
            logtime[fname] = (f"Previous timeout of {args.modelcheck}s", f"Previous timeout of {args.modelcheck}s")

    logtime["total time MC"] = time.time() - time_f
    logtime["Precompile PiTheta"] = ex.getEpistemicModel().compute_pi_theta_prime_time
    logtime["Precompile Marg(PiTheta)"] = ex.getEpistemicModel().compute_pi_theta_prime_marginalized_time

    return logtime


def model_checking_with_dec(ex, logtime):
    #print("BEGIN MC")

+1 −1
Changes for hanabi_loop.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@

import os, sys

p = os.path.abspath('.')
p = os.path.abspath('scripts')
sys.path.insert(1, p)

#<-- End of the trick
+8 −8
Changes for hanabi_smc.py: 8 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@

import os, sys

p = os.path.abspath('.')
p = os.path.abspath('scripts')
sys.path.insert(1, p)

#<-- End of the trick
@@ -398,7 +398,7 @@ class HanabiSMC(Example):
            # ALready calculated
            return self.ks

        t1 = time.time()
        #t1 = time.time()

        self.ex = HanabiExampleExplicitProba(self.nbA, self.nbC, nbCardsInHand=self.nbCH, tokens=self.tokens,
                                             random_pointed=self.random_generation)
@@ -532,7 +532,7 @@ class HanabiSMC(Example):
                real_functions = {}
                for a in self.agents:
                    with Timer("real_functions", show=False, father=tpi):
                        real_functions[a] = ks.omega[a].apply("x", self.manager.from_formula(rules))
                        real_functions[a] = ks.omega[a].apply("x", self.manager.from_formula(Top()))
                        #symb_rules = self.manager.from_formula(rules, vars=self.V, cache=ks.cache)
                        #symb_rels = self.manager.from_formula(relations[a], all_variables, cache=ks.cache)
                        #and_symbs = symb_rules.apply("x", symb_rels, cache=ks.cache)
@@ -541,12 +541,12 @@ class HanabiSMC(Example):
                        #real_functions[a] = and_symbs

                if self.normalize:

                    with Timer("probabilisation", incr=2, show=False, father=tpi):
                        pi = {}
                        for a, real_function in real_functions.items():
                            prime_varnames = [p for p in real_function.getVariables() if is_primed(p)]
                            pi[a] = real_function.marginalize_and_normalize(prime_varnames, cache=ks.cache)
                            res = ks.omega[a].apply("x", self.manager.from_formula(rules))
                            pi[a] = res.marginalize_and_normalize(prime_varnames, cache=ks.cache)
                else:
                    pi = real_functions

@@ -660,7 +660,7 @@ class HanabiSMC(Example):

        liste = []

        draw_atomes = [f"{a}-draws-{atome}" for atome in self.ks.pointed if "D" in atome]
        draw_atomes = [f"{a}-draws-{atome}" for atome in self.ks.pointed if DRAW_NAME in atome]

        for event in self.getEventModels():
            e_name2 = event.name if isinstance(event, Transformer) else event[0].name
@@ -920,7 +920,7 @@ if __name__ == "__main__":
                    else:
                        clean = []

                    with Timer("Product Update", show=False):
                    with Timer("Product Update in", show=False):
                        new = current.apply(a, cleaning=clean)

                    # print_datas(new, S5, proba)
@@ -940,4 +940,4 @@ if __name__ == "__main__":
    #      "S5", S5, "Proba", proba, "Prof", prof, "Random", random, "Seuil", seuil, "MC", modelcheck,
    #      "PU", product_update)

    Timer.memory.print(threshold=10)
    Timer.memory.print(threshold=0)
+1 −1
Changes for hanabi_smc_tests.py: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@

import os, sys

p = os.path.abspath('.')
p = os.path.abspath('scripts')
sys.path.insert(1, p)

#<-- End of the trick
+71 −17
Changes for launch_xp.sh: 71 added lines, 17 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
#!/bin/bash

# Simple use:
# ./launch.sh folder nb_loop timeout
@@ -19,7 +19,7 @@
# ./NEWEXP_graphes/
#  - differents graphes *.jpg

if [ "$#" -ne 3 ]; then
if [ "$#" -ne 4 ]; then
    echo "Illegal number of parameters"
    exit 1;
fi
@@ -34,51 +34,105 @@ mkdir "$Folder";

Nb_loops="$2"
Timeout="$3"
TimeoutMCPU="$4"

echo "$0 Folder: '$Folder', timeout: '$Timeout', nb_loops: '$Nb_loops'"
echo "$0 Folder: '$Folder', timeout: '$Timeout', timeout_mcpu: '$TimeoutMCPU' nb_loops: '$Nb_loops'"
date

run_process_loop () {
  begin="$1"
  shift 1
  for end; do
    filename=./"$Folder"/"$Prefix"_ch"$Cards_in_hand"_"$begin"-"$end"${proba}_n${i}

    filename=./"$Folder"/"$Prefix:"a"$agent"_ch"$Cards_in_hand"_"$begin"-"$end"${proba}"$Norm_flag"_x${i}

    echo $filename

    # shellcheck disable=SC2086
    if false; then
      /usr/bin/time -f "; %C; time; %es; memory; %MKB; cpu; %P;ch;${Cards_in_hand};end;${end}" -o "$filename"_time.txt \
      python3 scripts/hanabi_loop.py \
      -O -b "$begin" -e "$end" -step "$Nb_steps" -a 2 -ch "$Cards_in_hand" -xc "$Timeout" -lr 5 $Symbolic_flag -mc "$Timeout" -pu "$Timeout" $proba \
        python3 hanabi_loop.py \
        -O -b "$begin" -e "$end" -step "$Nb_steps" -a "$agent" -ch "$Cards_in_hand" -xc "$Timeout" -lr 5 $Symbolic_flag -mc "$TimeoutMCPU" -pu "$TimeoutMCPU" $proba $Norm_flag \
          >"$filename".txt &
##### REMOVE THE & HERE  ^  TO RUN EVERYTHING SEQUENTIALLY (useful to reproduce the experiments on a standard desktop machine)
       ##REMOVE THE & HERE ^  TO RUN EVERYTHING SEQUENTIALLY (useful to reproduce the experiments on a standard desktop machine)
      begin="$end"
    fi

  done
}

for i in $(seq 1 "$Nb_loops");
do
  for proba in "" "-p"
  for proba in "-p" # "" "-p"
  do

    ######## SMCPDEL
    Prefix=smcpdel
    Symbolic_flag='-s'
    Nb_steps=2


    if [[ "$TimeoutMCPU" -eq -1 ]]; then
      echo "Pas de MC ou PU en dénormalisé."

      Norm_flag=''

      agent=2
      Cards_in_hand=2
    run_process_loop 06 26 34 42 46 51
      run_process_loop 6 26 34 42 46 51
      Cards_in_hand=3
      run_process_loop 7 23 33 39 43 47 49 51
      Cards_in_hand=4
      run_process_loop 9 23 33 39 43 47 49 51
      Cards_in_hand=5
      run_process_loop 11 23 33 39 43 47 49 51

      agent=3
      Cards_in_hand=2
      run_process_loop 7 26 34 42 46 51
      Cards_in_hand=3
      run_process_loop 10 23 33 39 43 47 49 51
      Cards_in_hand=4
      run_process_loop 13 23 33

      agents=4
      Cards_in_hand=2
      run_process_loop 9 26 34 42 46 51
      Cards_in_hand=3
      run_process_loop 13 25 33 39 43 47 49 51


    else
      echo "MC et PU en normalisé et dénormalisé"

      for Norm_flag in "" "-n"
      do
        agent=2
        Cards_in_hand=2
        run_process_loop 6 26 34 42 46 51
        Cards_in_hand=3
        run_process_loop 7 23 33 39 43 47 49 51

        agent=3
        Cards_in_hand=2
        run_process_loop 7 26 34 42 46 51
        Cards_in_hand=3
        run_process_loop 10 23 33 39 43 47 49 51
      done

    fi

    #run_process_loop 50 51

    ######## explicit
    Prefix=expl
    Symbolic_flag=''
    Nb_steps=1
    Cards_in_hand=2
    run_process_loop 6 14 18
    #Prefix=expl
    #Symbolic_flag=''
    #Nb_steps=1
    #Cards_in_hand=2
    #run_process_loop 6 14 18

    Cards_in_hand=3
    run_process_loop 7 12 16
    #Cards_in_hand=3
    #run_process_loop 7 12 16

  done
  wait # does not overload the computing capacities with the biggest calculations: reproduces the run identically in CPU demand
@@ -94,5 +148,5 @@ echo "Print ${Folder}_all_report.csv"
rm -f "$Folder"_all_report_tmp.csv

# Generation of graphes to show results
python3 scripts/rendering_of_calculations.py ./"$Folder"/ ./"$Folder"_graphes
# python3 scripts/rendering_of_calculations.py ./"$Folder"/ ./"$Folder"_graphes
date
Loading