de cent20 » 28 Nov 2020, 09:48
citorva a écrit:Je vais essayer de la retrouver
D'ailleurs, j'ai modifié (énormément) mon script de bench en le rendant multi-processus:
bench_core.py, la base du système de test. Il fournit une interface entre l'interface et les tests et effectue les calculs:
Bonjour citorva,
J'ai testé ton script sur win10 depuis un l'IDE Thonny.
Dans un dossier, j'ai déposé les 4 fichiers requis :
Puis j'ai tenté de lancer le script bench.py et j'ai eu ce message d'erreur :
- Code: Tout sélectionner
Python 3.7.7 (bundled)
>>> %Run bench.py
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
usage: bench.py [-h] [-n NUMBER] [-s SEED] [-w WEB_DIM] [-d WEB_DENSITY]
[-b BATS_DENSITY] [-p PIT_DENSITY] [-m MAX_DURATION]
[-t THREADS] [-f UPDATE_FREQUENCY]
ia
bench.py: error: the following arguments are required: ia
J'ai l'impression qu'il est prévu pour être lancé uniquement en mode console, ou du moins qu'il faut il donner l'argument ia que j'imagine être le nom du fichier, par exemple web_test.py.
De ce que je comprend tout se règle ici :
- Code: Tout sélectionner
# Argument pour l'intelligence artificielle
parser.add_argument("ia", help="Fichier de l'IA à tester")
parser.add_argument('-n', "--number", default=100000, type=int, help="Nombre de tests à effectuer")
parser.add_argument('-s', "--seed", default=0xc0ffee, type=int, help="Graine aléatoire du benchmark")
parser.add_argument('-w', "--web-dim", default=36, type=int, help="Nombre de corniches")
parser.add_argument("-d", "--web-density", default=0.05, type=float,
help="Densité moyenne de voisine à chaque corniche")
parser.add_argument("-b", "--bats-density", default=0.1, type=float, help="Densité de chauve souris par parties")
parser.add_argument("-p", "--pit-density", default=0.15, type=float, help="Densité de puit par parties")
parser.add_argument("-m", "--max-duration", default=20, type=float, help="Durée maximum d'une partie en seconde")
parser.add_argument("-t", "--threads", default=1, type=int, help="Nombre de fils d'exécution pour les tests")
parser.add_argument("-f", "--update-frequency", default=24, type=int, help="Fréquence de rafraichssement de l'interface")
Comment je branche le nom de mon fichier dans ton script ?
En tout cas il est superbe, il y a de nombreuses d'astuces à étudier, rien que le multi thread sera passionnant à analyser (quand j'aurais le temps).
En mettant ceci, (testé avec ou sans .py) :
- Code: Tout sélectionner
parser.add_argument("-ia", "--ia", default="web_test", type=str, help="Fichier de l'IA à tester") # Modifié
j'ai un nouveau bloc d'erreur :
- Code: Tout sélectionner
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Python\defi2020\leviathan\recherche citorva v2\bench.py", line 367, in <module>
args.bats_density
File "D:\Python\defi2020\leviathan\recherche citorva v2\bench_core.py", line 131, in __init__
self.mgr.start()
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\managers.py", line 563, in start
self._process.start()
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\micro\AppData\Local\Programs\Thonny\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.