Commit 63404a99 authored by SINDT--BARET Yanis's avatar SINDT--BARET Yanis
Browse files

[New] Update of python module

Now create a result.json for each simulation, with a new seed for each one.
parent 259d9195
import asyncio
import json
import subprocess
import os
import random
async def run(cmd):
proc = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE)
stdout, stderr = await proc.communicate()
print(f'[{cmd!r} exited with {proc.returncode}]')
if stdout:
print(f'[stdout]\n{stdout.decode()}')
if stderr:
print(f'[stderr]\n{stderr.decode()}')
def create_basic_file(path:str,index:int) -> None:
with open(path, "r") as file:
data_json = json.load(file)
data_json["seed"] = index
old_path_splited = path.split(".")
new_path = f"{old_path_splited[0]}_{index}.{old_path_splited[1]}"
data_json["seed"] = index ### random.randint(1,1000000) aussi dans l'optimal pour faire 2 série de répétitions différentes
old_path_splited = path.split(".json")
new_path = f"{old_path_splited[0]}_{index}.json"
with open(new_path,"w") as result_file:
json.dump(data_json,result_file)
asyncio.run(run(
"""
cd /home/yanissb/CLionProjects/sswm_prototype/build
cmake ..
make
"""
))
def change_resultjson_seed(index :int, result_id: str, path="") -> None:
with open(f"{path}result.json", "r") as file:
data_json = json.load(file)
data_json["seed"] = random.randint(1,1000000)
with open(f"{path}result_{result_id}_{index}.json","w") as result_file:
json.dump(data_json,result_file)
if __name__ == '__main__':
result_id : str = input("Give a short ID (3 char) to find result of the simulation : ")
load_basic : bool = input("Do we need to create all basic files ? (y/n) : ")
nb_hikes = int(input("How many hikes do you want to do ? : ")) #faire un try except
inversion_rate = int(input("Which probability of inversion ? : "))
nb_gen = int(input("How many generation ? : "))
is_neutral_mut = input("Do you allow neutral mutation ? (y/n) : ").lower()
for i in range(nb_hikes) :
create_basic_file("examples/sswm_project/basic.json",i)
asyncio.run(run(
f"""
cd examples/sswm_project
../../build/bin/module_create basic_{i}.json
../../build/bin/sswm result.json {inversion_rate} {nb_gen} {is_neutral_mut} {i}
"""
))
os.chdir("/home/yanissb/CLionProjects/sswm_prototype/examples/sswm_project")
if load_basic == "y":
for i in range(1,nb_hikes+1):
create_basic_file("basic.json",i)
for i in range(1,nb_hikes+1) :
a = subprocess.Popen(args=["../../build/bin/module_create", f"basic_{i}.json"])
a.wait()
change_resultjson_seed(i,result_id)
b = subprocess.Popen(args=["../../build/bin/sswm"
,f"result_{result_id}_{i}.json",
str(inversion_rate),
str(nb_gen),
str(is_neutral_mut),
str(i)])
b.wait()
print(f"\n{i}")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment