diff --git a/gen.sage b/gen.sage index 3fb55899dc3b6e9ac25983b044408408fcb12253..67012171d3f41ca28698772b29e7bdc122c8df96 100644 --- a/gen.sage +++ b/gen.sage @@ -153,16 +153,17 @@ class ResultantsCtx(Name, System): self.n_ctx = IntegerCtx(n, default=3, message="Dimension ?") self.d_ctx = IntegerCtx(d, default=3, message="Degree ?") - variables = [f"x_{i}" for i in range(self.n_ctx.value)] - self.ring = PolynomialRing( - CC, names=variables) + dense_ctx = DenseCtx([self.d_ctx.value for _ in range(self.n_ctx.value)]) + self.ring = dense_ctx.ring + variables = list(map(str, self.ring.gens())) + self.system = dense_ctx.system + + assert "y" not in variables Cpy = PolynomialRing(CC, names=["y"] + variables) - self.system = [] - for _ in range(self.n_ctx.value): - f = Cpy.random_element(degree=self.d_ctx.value, terms=1000) - g = Cpy.random_element(degree=self.d_ctx.value, terms=1000) - h = g.resultant(f, Cpy.gens()[0]) - self.system.append(self.ring(h)) + f = Cpy.random_element(degree=self.d_ctx.value, terms=1000) + g = Cpy.random_element(degree=self.d_ctx.value, terms=1000) + h = g.resultant(f, Cpy.gens()[0]) + self.system[0] = self.ring(h) self.degrees = [f.degree() for f in self.system] self.name = Path( "resultants" + f"-{self.n_ctx.name}-{self.d_ctx.name}") diff --git a/packages/adaptive.py b/packages/adaptive.py index 8b221f9c08daff7cbbbfbc9b38681aaa9f87ea07..6388b03271e316fd11c50bd9b8920d5fa9567014 100644 --- a/packages/adaptive.py +++ b/packages/adaptive.py @@ -2,10 +2,11 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument("file", help = "A file containing data test") +parser.add_argument("algpath_path", help = "A algpath binary that supports --arithmetic arb-reckless") args = parser.parse_args() command = open("command.sh", "w") command.write(f"""#!/bin/sh -/home/aguillem/documents/travail/these/numerical_algebraic_geometry/algpath/algpath/target/release/algpath {args.file} --diff backward --homogenize --arithmetic arb-reckless --jobs 1""") +{args.algpath_path} {args.file} --diff backward --homogenize --arithmetic arb-reckless --jobs 1""") command.close() \ No newline at end of file diff --git a/packages/algpath.py b/packages/algpath.py index 09167144cf0c272c05c3c2e5258dc7b08765e8ff..683af2c2e0937f7111e6896933fc61e99e92c606 100644 --- a/packages/algpath.py +++ b/packages/algpath.py @@ -2,10 +2,11 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument("file", help = "A file containing data test") +parser.add_argument("algpath_path", help = "A algpath branch main binary") args = parser.parse_args() command = open("command.sh", "w") command.write(f"""#!/bin/sh -algpath {args.file} --homogenize --diff backward --jobs 1""") +{args.algpath_path} {args.file} --homogenize --diff backward --jobs 1""") command.close() \ No newline at end of file diff --git a/packages/homotopycontinuation.py b/packages/homotopycontinuation.py index 23206486c5585ed58864eaf82e716e51e629022f..08ed8257b9fdbd4755cf1d0f2be3455a790ce6a2 100644 --- a/packages/homotopycontinuation.py +++ b/packages/homotopycontinuation.py @@ -4,10 +4,11 @@ import sys parser = argparse.ArgumentParser() parser.add_argument("file", help = "A file containing data test") +parser.add_argument("julia_path", help = "A julia binary path") args = parser.parse_args() command = open("command.sh", "w") command.write(f"""#!/bin/sh -julia {os.path.dirname(sys.argv[0])}/_homotopycontinuation.jl {args.file}""") +{args.julia_path} {os.path.dirname(sys.argv[0])}/_homotopycontinuation.jl {args.file}""") command.close() \ No newline at end of file diff --git a/packages/macaulay2.py b/packages/macaulay2.py index d95af9789f11c26bc2731e5f5b884797bf85cc0c..81b452572d00776022138dc4902d61edd4f19bcd 100644 --- a/packages/macaulay2.py +++ b/packages/macaulay2.py @@ -4,6 +4,7 @@ import argparse # Parsing input arguments parser = argparse.ArgumentParser() parser.add_argument("file", help = "A file containing data test") +parser.add_argument("m2_path", help = "A m2 binary path") args = parser.parse_args() # Recovering the data from the json file given by arguments @@ -48,8 +49,8 @@ exit(); script.close() command = open("command.sh", "w") -command.write("""#!/bin/sh +command.write(f"""#!/bin/sh -M2 script.m2 --silent +{args.m2_path} script.m2 --silent """) command.close() diff --git a/packages/sirocco.py b/packages/sirocco.py index 39132a2731b027ed36c028d2447c5a1a1e3792f7..0b5240a74eb8b92cd90a6416fe970c4714c5d429 100644 --- a/packages/sirocco.py +++ b/packages/sirocco.py @@ -3,6 +3,7 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument("file", help = "A file containing data test") +parser.add_argument("sage_path", help = "A sage binary path") args = parser.parse_args() data_file = open(args.file) @@ -47,7 +48,7 @@ print("{\\"time\\" : \\"" + str(time.time() - start) + "\\", \\"steplist\\" : " """ % (vars_parameter, vars_data, data["system"], data["fiber"], float(data["path"][0][0]), float(data["path"][1][0]))) command = open("command.sh", "w") -command.write("""#!/bin/sh +command.write(f"""#!/bin/sh -sage script.sage""") +{args.sage_path} script.sage""") command.close() \ No newline at end of file diff --git a/runtest.py b/runtest.py index 8c1cfd4bc2a9c5d62fc2477cda0ff8c945df2bb8..b38e36899857b3450f4ba6f141fe7017174ce350 100644 --- a/runtest.py +++ b/runtest.py @@ -7,13 +7,19 @@ import re from datetime import datetime from pathlib import Path -parser = argparse.ArgumentParser(description = "A description") -parser.add_argument("pkg", help = "The package which is tested. Should be packages/<pkg_name>.py e.g. packages/algpath.py") -parser.add_argument("data", help = "The system which is tested. Shoud be data/<test_name>.json e.g. data/linear_dense-10_all-paths_1.json") -parser.add_argument("-p", "--perf", action = 'store_true', default = False, help = "perf stat the benchmark and put the result in perflog.txt") -parser.add_argument("-t", "--timeout", nargs = "?", const = "300", help = "To run the benchmark with a timeout. Should be written as <number><unit> where <unit> may be nothing (this implicitely means seconds), s, m or h, e.g. 1h") -parser.add_argument("-m", "--mem", nargs = "?", const = "8G", help = "Maximum amount of memory used. Should be written as <number><unit> where <unit> may be nothing, K, M or G, e.g. 100M") -parser.add_argument("-n", "--norun", action = 'store_true', default = False, help = "To only generate script and command") +parser = argparse.ArgumentParser(description="A description") +parser.add_argument( + "pkg", help="The package which is tested. Should be packages/<pkg_name>.py e.g. packages/algpath.py") +parser.add_argument( + "data", help="The system which is tested. Shoud be data/<test_name>.json e.g. data/linear_dense-10_all-paths_1.json") +parser.add_argument("-p", "--perf", action='store_true', default=False, + help="perf stat the benchmark and put the result in perflog.txt") +parser.add_argument("-t", "--timeout", nargs="?", const="300", + help="To run the benchmark with a timeout. Should be written as <number><unit> where <unit> may be nothing (this implicitely means seconds), s, m or h, e.g. 1h") +parser.add_argument("-m", "--mem", nargs="?", const="8G", + help="Maximum amount of memory used. Should be written as <number><unit> where <unit> may be nothing, K, M or G, e.g. 100M") +parser.add_argument("-n", "--norun", action='store_true', + default=False, help="To only generate script and command") args = parser.parse_args() pkg_path = Path(args.pkg) @@ -27,19 +33,29 @@ assert pkg_path.exists(), tmp_pkg_str data = data_path.stem pkg = pkg_path.stem +pkg_binary_dict = {"homotopycontinuation": "julia", "sirocco": "sage", + "macaulay2": "M2", "algpath": "algpath", "adaptive": "packages/adaptive"} + print(f"Benchmarking {pkg} on {data_path}" + args.perf*" (with perf stat)") print("Creating benchmark folder...") -bench_path = (Path("benchmarks").joinpath(*data_path.with_suffix("").parts[1:]) / pkg) +bench_path = (Path("benchmarks").joinpath( + *data_path.with_suffix("").parts[1:]) / pkg) bench_path.mkdir(parents=True, exist_ok=True) print("Generating script and command...") -absolute_pkg_path = pkg_path.resolve() -absolute_data_path = data_path.resolve() -absolute_bench_path = bench_path.resolve() + +auxi = Path("/".join([".." for _ in bench_path.parts])) + +if pkg in ["adaptive"]: + pkg_binary_path = auxi / pkg_binary_dict[pkg] +else: + pkg_binary_path = pkg_binary_dict[pkg] + os.chdir(bench_path) -subprocess.run(["python3", f"{absolute_pkg_path}", f"{absolute_data_path}"]) -subprocess.run(["chmod", "+x", str(absolute_bench_path / "command.sh")]) +subprocess.run(["python3", f"{auxi / pkg_path}", + f"{auxi / data_path}", f"{pkg_binary_path}"]) +subprocess.run(["chmod", "+x", str("command.sh")]) # assert 1 == 0 if not args.norun: @@ -67,7 +83,7 @@ if not args.norun: return val def timeout_parsing(s): - auxi = re.split('(\d+)',s) + auxi = re.split('(\d+)', s) val = int(auxi[1]) try: unit = auxi[2] @@ -97,7 +113,7 @@ if not args.norun: memory_max = str(args.mem) info_dict = { "datetime": str(datetime.now()), - "return code" : None, + "return code": None, "timeout": timeout_s, "timeout error": False, "memory": memory_b, @@ -106,7 +122,7 @@ if not args.norun: "killed manually": True, } - json.dump(info_dict, info_file, indent = 2) + json.dump(info_dict, info_file, indent=2) info_file.close() out_file = open("out.json", "w") @@ -114,17 +130,20 @@ if not args.norun: print("Running script...") - cmd = ["systemd-run", "--scope", "--user", "-p", f"MemoryMax={memory_b}", "-p", "MemorySwapMax=0"]*(memory_b != None) + ["perf", "stat", "-o", "perflog.txt"]*args.perf + ["taskset", "1", "./command.sh"] + cmd = ["systemd-run", "--scope", "--user", "-p", f"MemoryMax={memory_b}", "-p", "MemorySwapMax=0"]*( + memory_b != None) + ["perf", "stat", "-o", "perflog.txt"]*args.perf + ["taskset", "1", "./command.sh"] - p = subprocess.Popen(cmd, start_new_session = True, stdout = out_file, stderr = log_file) + p = subprocess.Popen(cmd, start_new_session=True, + stdout=out_file, stderr=log_file) try: - _, _ = p.communicate(timeout = timeout_s) + _, _ = p.communicate(timeout=timeout_s) log_file.close() log_file = open("log.txt", "r") log = log_file.read() try: user_unit = re.findall(r"run.*scope", log)[0] - log_systemd = subprocess.run(["journalctl", "--user-unit", user_unit], capture_output = True).stdout + log_systemd = subprocess.run( + ["journalctl", "--user-unit", user_unit], capture_output=True).stdout except: log_systemd = "" @@ -146,7 +165,7 @@ if not args.norun: info_dict["killed manually"] = False info_dict["return code"] = p.returncode info_file = open("info.json", "w") - json.dump(info_dict, info_file, indent = 2) + json.dump(info_dict, info_file, indent=2) info_file.close() out_file = open("out.json", "r") @@ -157,4 +176,4 @@ if not args.norun: else: out_file.close() out_file = open("out.json", "w") - json.dump(result, out_file, indent = 2) \ No newline at end of file + json.dump(result, out_file, indent=2) diff --git a/synthesize.py b/synthesize.py index 7b4d97c250d7ba5a797c6ce7b195cc83bba5a46e..7908c31d72452fda091bc1fa839f6be4920cb9c5 100644 --- a/synthesize.py +++ b/synthesize.py @@ -198,7 +198,7 @@ def _table(data, branch, node): return [{"str": "", "w": 1}] # Packages handling - if key in ["homotopycontinuation", "algpath", "macaulay2", "sirocco"]: + if key in ["homotopycontinuation", "algpath", "macaulay2", "sirocco", "adaptive"]: dir = f"benchmarks/{data}/{key}/" if not os.path.exists(dir): return [{"str": "not benchmarked", "w": len(get_leaves(node))}]