Refactoring
This commit is contained in:
parent
0bf4dc6e9f
commit
28f3d5b140
1 changed files with 88 additions and 42 deletions
|
|
@ -1,39 +1,43 @@
|
||||||
import logging
|
import logging
|
||||||
|
import argparse
|
||||||
import pathlib
|
import pathlib
|
||||||
import configparser
|
import os
|
||||||
|
|
||||||
|
from threading import active_count
|
||||||
|
from multiprocessing import Pool
|
||||||
|
from multiprocessing.pool import ThreadPool
|
||||||
|
from random import shuffle
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from functools import partial
|
||||||
from Code.S_run_aifeynman import run_aifeynman
|
|
||||||
|
|
||||||
|
|
||||||
|
from S_run_aifeynman import run_aifeynman
|
||||||
|
|
||||||
|
_CFG = {
|
||||||
|
"dataset_path" : "../Feynman_without_units/",
|
||||||
|
"operations_file" : "./14ops.txt",
|
||||||
|
"polynomial_degree" : 3,
|
||||||
|
"number_of_epochs" : 500,
|
||||||
|
"bruteforce_time" : 60,
|
||||||
|
"test_percentage" : 0,
|
||||||
|
}
|
||||||
|
|
||||||
class RunAll:
|
class RunAll:
|
||||||
"""
|
"""
|
||||||
Run the solver on all the whole dataset
|
Run the solver on the whole dataset
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *, cfg_path: Path):
|
def __init__(self, *, cfg=_CFG):
|
||||||
logging.basicConfig(filename="output.log", level=logging.DEBUG)
|
logging.basicConfig(filename="output_no_units_parallel.log", level=logging.DEBUG)
|
||||||
self.config = configparser.ConfigParser()
|
self.cfg = cfg
|
||||||
self.config.read(cfg_path)
|
|
||||||
self.cfg = self.config["Default"]
|
|
||||||
self.print_results()
|
|
||||||
self.results = {}
|
self.results = {}
|
||||||
|
|
||||||
|
|
||||||
self.run_solver()
|
|
||||||
|
|
||||||
def log_results(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def print_results(self):
|
def print_results(self):
|
||||||
table = [
|
table = []
|
||||||
["foo", 696000, 1989100000],
|
for file, sol in self.results.items():
|
||||||
["bar", 6371, 5973.6],
|
table.append(sol[-1])
|
||||||
["baz", 1737, 73.5],
|
|
||||||
["qux", 3390, 641.85],
|
|
||||||
]
|
|
||||||
print(tabulate(
|
print(tabulate(
|
||||||
table,
|
table,
|
||||||
headers=[
|
headers=[
|
||||||
|
|
@ -45,25 +49,67 @@ class RunAll:
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def run_solver(self):
|
def run_solver(self, dirs=None):
|
||||||
path = Path(self.cfg["dataset_path"])
|
if not dirs:
|
||||||
for child in path.iterdir():
|
path = Path(self.cfg["dataset_path"])
|
||||||
self.results[str(child).split("/")[-1]] = run_aifeynman(
|
dirs = list(path.iterdir())
|
||||||
pathdir="/home/aziz/lambda_lab/AI-Feynman/example_data/",#str(path.resolve()) + "/",
|
shuffle(dirs) # Shuffle to sample a different file each time
|
||||||
filename="example2.txt",#str(child).split("/")[-1],
|
|
||||||
BF_try_time=int(self.cfg["bruteforce_time"]),
|
else:
|
||||||
BF_ops_file_type=Path(self.cfg["operations_file"]),
|
path=Path(self.cfg["dataset_path"])
|
||||||
polyfit_deg=int(self.cfg["polynomial_degree"]),
|
child = dirs
|
||||||
NN_epochs=int(self.cfg["number_of_epochs"]),
|
|
||||||
vars_name=[],
|
|
||||||
test_percentage=int(self.cfg["test_percentage"]),
|
# for child in dirs:
|
||||||
)
|
# print(child)
|
||||||
logging.info(self.results)
|
print(f"Process PID: {os.getpid()} ---------------- Number of threads: {active_count()}" )
|
||||||
break
|
self.results[str(child).split("/")[-1]] = run_aifeynman(
|
||||||
|
pathdir=str(path.resolve()) + "/",
|
||||||
|
filename=str(child).split("/")[-1],
|
||||||
|
BF_try_time=int(self.cfg["bruteforce_time"]),
|
||||||
|
BF_ops_file_type=Path(self.cfg["operations_file"]),
|
||||||
|
polyfit_deg=int(self.cfg["polynomial_degree"]),
|
||||||
|
NN_epochs=int(self.cfg["number_of_epochs"]),
|
||||||
|
vars_name=[],
|
||||||
|
test_percentage=int(self.cfg["test_percentage"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
logging.info(self.results)
|
||||||
|
print("@"*120)
|
||||||
|
print("@"*120)
|
||||||
|
|
||||||
|
self.print_results()
|
||||||
|
|
||||||
|
|
||||||
|
def get_files(dirs, chunks=5):
|
||||||
|
dirs = list(path.iterdir())
|
||||||
|
dirs = [file for file in dirs if not (str(file).endswith("test") or str(file).endswith("train"))]
|
||||||
|
for i in range(0, len(dirs), chunks):
|
||||||
|
yield dirs[i : i + chunks]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
cfg_path = pathlib.Path("/home/aziz/lambda_lab/AI-Feynman/configs.cfg")
|
|
||||||
if cfg_path.exists():
|
#cfg_path = pathlib.Path("/home/aziz/lambda_lab/AI-Feynman/configs.cfg")
|
||||||
RunAll(cfg_path=cfg_path)
|
#if cfg_path.exists():
|
||||||
else:
|
# RunAll(cfg_path=cfg_path)
|
||||||
print(f"No such a file {cfg_path}")
|
#else:
|
||||||
|
# print(f"No such a file {cfg_path}")
|
||||||
|
|
||||||
|
solver = RunAll().run_solver
|
||||||
|
path = Path(_CFG["dataset_path"])
|
||||||
|
#dirs = list(path.iterdir())
|
||||||
|
#chunked_dirs = list(get_files(dirs, chunks=24))
|
||||||
|
# print(chunked_dirs[0], len(chunked_dirs[0]))
|
||||||
|
# for dd in chunked_dirs:
|
||||||
|
# pool = Pool(len(dd))
|
||||||
|
# print(dd, len(dd))
|
||||||
|
# pool.map(print, dd)
|
||||||
|
# pool.map(solver, dd)
|
||||||
|
# pool.close()
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Solver')
|
||||||
|
parser.add_argument('--file', help='Enter file path')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
solver(args.file)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue