Skip to content

Commit

Permalink
Do no longer write by default
Browse files Browse the repository at this point in the history
  • Loading branch information
APN-Pucky committed Apr 4, 2024
1 parent a66d01b commit 954ffe8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
19 changes: 8 additions & 11 deletions feynamp/form/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,12 @@ def compute_squared(fds: List[FeynmanDiagram], fm: FeynModel, tag=False):
)
debug(f"{rr=}")

ret = sympy.simplify(
sympy.parse_expr(
rr.replace("Mom_", "")
.replace(".", "_")
.replace("^", "**")
.replace("mss", "s")
.replace("msu", "u")
.replace("mst", "t")
)
* sympy.parse_expr("*".join([*get_color_average(fds), *get_spin_average(fds)]))
)
ret = sympy.parse_expr(
rr.replace("Mom_", "")
.replace(".", "_")
.replace("^", "**")
.replace("mss", "s")
.replace("msu", "u")
.replace("mst", "t")
) * sympy.parse_expr("*".join([*get_color_average(fds), *get_spin_average(fds)]))
return ret
43 changes: 19 additions & 24 deletions feynamp/form/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@ def string_to_form(s):
return s


def run_parallel(
init, cmds, variables, show=False, write=False, keep_form_file=True, threads=None
):
def run_parallel(init, cmds, variables, show=False, keep_form_file=False, threads=None):
global count
count = count + 1
rets = []
if threads is None:
threads = os.cpu_count()
with open("form" + str(count) + ".frm", "w") as frm:
with form.open(keep_log=1000, args=["tform", f"-w{threads}"]) as f:
txt = "" + init
for i, s in enumerate(variables):
Expand All @@ -53,39 +50,37 @@ def run_parallel(
for i, s in enumerate(variables):
txt += f"print TMP{i};.sort;"
f.write(txt)
if write:
frm.write(txt)
if keep_form_file:
with open("form" + str(count) + ".frm", "w") as frm:
frm.write(txt)
for i, s in enumerate(variables):
rets.append(f.read(f"TMP{i}"))
# What is this ?
# r = re.sub(r"\+factor_\^?[0-9]*", r"", r).strip("*")
if show:
for r in rets:
print(r + "\n")
# delete frm file
if not keep_form_file:
os.remove("form" + str(count) + ".frm")
assert len(rets) == len(variables)
return rets


def run(s, show=False, keep_form_file=True):
def run(s, show=False, keep_form_file=False):
global count
count = count + 1
with open("form" + str(count) + ".frm", "w") as frm:
with form.open(keep_log=1000, args=["tform", "-w16"]) as f:
local = s.split("Local")[1].split("=")[0].strip()
txt = s + "print " + local + ";.sort;"
f.write(txt)
# frm.write(txt)
r = f.read("" + local)
r = re.sub(r"\+factor_\^?[0-9]*", r"", r).strip("*")
if show:
print(r + "\n")
# delete frm file
if not keep_form_file:
os.remove("form" + str(count) + ".frm")
return r
with form.open(keep_log=1000, args=["tform", "-w16"]) as f:
local = s.split("Local")[1].split("=")[0].strip()
txt = s + "print " + local + ";.sort;"
f.write(txt)
# frm.write(txt)
r = f.read("" + local)
r = re.sub(r"\+factor_\^?[0-9]*", r"", r).strip("*")
if show:
print(r + "\n")
# delete frm file
if keep_form_file:
with open("form" + str(count) + ".frm", "w") as frm:
frm.write(txt)
return r


def sympyfy(string_expr):
Expand Down

0 comments on commit 954ffe8

Please sign in to comment.