Skip to content

Commit

Permalink
Add debugging information for celer-g4 and celer-sim (celeritas-proje…
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj authored Nov 16, 2024
1 parent e390d55 commit f8b2d56
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
19 changes: 9 additions & 10 deletions app/celer-g4/test-harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
import re
import subprocess
from os import environ, path
from os import environ, getcwd, path
from pprint import pprint
from sys import exit, argv, stderr

Expand Down Expand Up @@ -96,10 +96,11 @@ def strtobool(text):
})

kwargs = {}
args = [exe, inp_file]
if use_celeritas:
# IO through streams should work with celeritas or g4 as driver, but just
# do it here as an example
inp_file = "-"
args = [exe, inp_file]
inp["output_file"] = "-"
inp["slot_diagnostic_prefix"] = f"slot-diag-{ext}-"

Expand All @@ -110,13 +111,11 @@ def strtobool(text):
env=env,
)

print(inp)

with open(f"{problem_name}.inp.json", "w") as f:
with open(inp_file, "w") as f:
json.dump(inp, f, indent=1)

print("Running", exe, inp_file, file=stderr)
result = subprocess.run([exe, inp_file], **kwargs)
print("Running", exe, inp_file, "from", getcwd(), file=stderr)
result = subprocess.run(args, **kwargs)

if use_celeritas:
# Decode the output, fail if the run failed
Expand All @@ -139,10 +138,10 @@ def strtobool(text):
except:
pass
else:
outfilename = f'{problem_name}.out.failed.json'
with open(outfilename, 'w') as f:
out_file = f'{problem_name}.out.failed.json'
with open(out_file, 'w') as f:
json.dump(j, f, indent=1)
print("Failure written to", outfilename, file=stderr)
print("Failure written to", out_file, file=stderr)
j = {}

exit(result.returncode)
Expand Down
7 changes: 3 additions & 4 deletions app/celer-geo/test-harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""
import json
import subprocess
from os import environ
from sys import exit, argv
from os import environ, getcwd
from sys import exit, argv, stderr
from pathlib import Path

try:
Expand Down Expand Up @@ -65,9 +65,8 @@ def decode_line(jsonline):
for c in commands:
json.dump(c, f)
f.write('\n')
print("Wrote input to", filename)

print("Running", exe)
print("Running", exe, filename, "from", getcwd(), file=stderr)
result = subprocess.run([exe, filename],
stdout=subprocess.PIPE)
if result.returncode:
Expand Down
45 changes: 27 additions & 18 deletions app/celer-sim/simple-driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
import re
import subprocess
from os import environ, path
from os import environ, getcwd, path
from sys import exit, argv, stderr

try:
Expand Down Expand Up @@ -51,11 +51,16 @@ def strtobool(text):

if geant_exp_exe:
physics_filename = run_name + ".root"
print("Running", geant_exp_exe, file=stderr)
result_ge = subprocess.run(
[geant_exp_exe, geometry_filename, "-", physics_filename],
input=json.dumps(physics_options).encode()
)
inp_file = f'{run_name}.geant.json'
with open(inp_file, 'w') as f:
json.dump(physics_options, f, indent=1)

args = [geant_exp_exe, geometry_filename, inp_file, physics_filename]
print("Running", args, file=stderr)

# Test using stdin instead of filename
args[2] = "-"
result_ge = subprocess.run(args, input=json.dumps(physics_options).encode())

if result_ge.returncode:
print(f"fatal: {geant_exp_exe} failed with error {result_ge.returncode}")
Expand All @@ -72,7 +77,7 @@ def strtobool(text):
if not rootout_filename and "cms" in geometry_filename:
simple_calo = ["si_tracker", "em_calorimeter"]

num_tracks = 128*32 if use_device else 32
num_tracks = 128 * 32 if use_device else 32
num_primaries = 3 * 15 # assuming test hepmc input
max_steps = 512 if physics_options['msc'] else 128

Expand Down Expand Up @@ -115,25 +120,28 @@ def strtobool(text):
'slot_diagnostic_prefix': f"slot-diag-{run_name}-",
}

with open(f'{run_name}.inp.json', 'w') as f:
inp_file = f'{run_name}.inp.json'
with open(inp_file, 'w') as f:
json.dump(inp, f, indent=1)

exe = environ.get('CELERITAS_EXE', './celer-sim')
print("Running", exe, file=stderr)
result = subprocess.run([exe, '-'],
input=json.dumps(inp).encode(),
stdout=subprocess.PIPE)
print("Running", exe, inp_file, "from", getcwd(), file=stderr)
result = subprocess.run(
[exe, '-'],
input=json.dumps(inp).encode(),
stdout=subprocess.PIPE
)
if result.returncode:
print("fatal: run failed with error", result.returncode)
try:
j = json.loads(result.stdout.decode())
except:
pass
else:
outfilename = f'{run_name}.out.failed.json'
with open(outfilename, 'w') as f:
out_file = f'{run_name}.out.failed.json'
with open(out_file, 'w') as f:
json.dump(j, f, indent=1)
print("Failure written to", outfilename, file=stderr)
print("Failure written to", out_file, file=stderr)

exit(result.returncode)

Expand All @@ -147,10 +155,10 @@ def strtobool(text):
print("fatal:", str(e))
exit(1)

outfilename = f'{run_name}.out.json'
with open(outfilename, 'w') as f:
out_file = f'{run_name}.out.json'
with open(out_file, 'w') as f:
json.dump(j, f, indent=1)
print("Results written to", outfilename, file=stderr)
print("Results written to", out_file, file=stderr)

run_output =j['result']['runner']
time = run_output['time'].copy()
Expand All @@ -161,4 +169,5 @@ def strtobool(text):
else:
# Step times disabled on CPU from input
assert steps is None

print(json.dumps(time, indent=1))

0 comments on commit f8b2d56

Please sign in to comment.