Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remaining Python examples can be chained #1174

Merged
merged 42 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
bbfc60f
Python digitization can now be chained with addDigitization()
Feb 7, 2022
b2f41e8
specify configureDigitization's argument types
Feb 7, 2022
00d2977
improved addParticleGun wrapper, also accepts tuple as kwarg
Feb 7, 2022
0a46403
buildITkGeometry can optionally use a JSON file instead of doing ever…
Feb 7, 2022
1c599a2
Start of full-chain ITk Python example. Just particle_gun, fatras, an…
Feb 8, 2022
ab7f2ba
use fixed starting random number seed
Feb 10, 2022
c423a9f
can change itk.py logging level
Feb 8, 2022
b15103f
find digi file correctly in test_vertex_fitting_reading
Feb 22, 2022
aa3b883
addSeeding in seeding.py
Feb 22, 2022
a52a467
keep runSeeding logging level. Add function help.
Feb 22, 2022
1eb905b
runSeeding: remove particle selection in fatras
Feb 22, 2022
edfde38
seeding.py can also setup truth-seeded and truth-estimated seeding
Feb 25, 2022
8e0c1c4
@NamedTypeArgs(arg=Type,...) decorator to simplify named type argumen…
Feb 25, 2022
aa5352e
addSeeding takes TruthSeedRanges() and ParticleSmearingSigmas()
Feb 26, 2022
8d83783
SeedFinderConfig settings can be passed to addSeeding
Feb 28, 2022
3c8f07f
addCKFTracks in ckf_tracks.py
Mar 2, 2022
eecee17
fix RootTrackParameterWriter inputParticles
Mar 8, 2022
8ddf56d
display acts.examples pybind11 calls with DEBUG logLevel
Mar 8, 2022
ef76999
improved pybind11 debugging
Mar 9, 2022
a8bdb3f
fix seeding for ckf_tracks.py
Mar 11, 2022
66d522a
Python format
Mar 11, 2022
d14ddf0
trivial simplification
Mar 11, 2022
a55ee9a
complete full_chain_itk.py with most basic setup
Mar 11, 2022
707229c
new pythia8.addPythia8 replaces common.addPythia8
Mar 21, 2022
8356f25
fix formatting
Mar 21, 2022
41e4c6c
reproduce common.addPythia8 using pythia8.addPythia8
Mar 21, 2022
4a9e1fe
use Sequence[] in Python function type hints
Mar 22, 2022
84e7318
another attempt to get function argument hints working in the CI (pyt…
Mar 22, 2022
9712724
addVertexFitting sets up vertex fitting
Mar 25, 2022
977476c
common.addPythia8 comment
Mar 29, 2022
f0394c5
fix phys_perf_mon.sh for different output directory
Mar 29, 2022
17259b6
Only do Geant4 Python tests if it is enabled
Mar 30, 2022
4364dfa
RootVertexPerformanceWriter warning OK when run from pytest Examples/…
Mar 30, 2022
b9481aa
pytest: write performance_vertexing.root to test output dir
Mar 30, 2022
eae4e9d
turn off VERBOSE logging in runCKFTracks
Mar 30, 2022
2a52ea4
runCKFTracks doesn't write particle-gun and fatras output
Mar 30, 2022
441caa4
fix CKFPerformanceWriter inputParticles
Mar 30, 2022
ffceb7a
remove spurious Optional[] function argument hints
Mar 31, 2022
14d245a
change default seeding input from particles_final -> particles_initia…
Mar 31, 2022
e9d56c2
add comment
Mar 31, 2022
46fc140
Set missing TruthSeedRanges. Add missing arguments in docstrings foun…
Apr 1, 2022
4539ad2
Merge branch 'main' into pybind6
kodiakhq[bot] Apr 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CI/physmon/phys_perf_mon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -e

outdir=$1
[ -z "$outdir" ] && outdir=physmon
mkdir -p $outdir

refdir=CI/physmon/reference
Expand Down Expand Up @@ -35,26 +36,26 @@ function run() {


run \
physmon/performance_ckf_tracks_truth_smeared.root \
$outdir/performance_ckf_tracks_truth_smeared.root \
paulgessinger marked this conversation as resolved.
Show resolved Hide resolved
$refdir/performance_ckf_tracks_truth_smeared.root \
--title "CKF truth smeared" \
-c CI/physmon/ckf_truth_smeared.yml \
-o $outdir/ckf_truth_smeared.html \

run \
physmon/performance_ckf_tracks_truth_estimated.root \
$outdir/performance_ckf_tracks_truth_estimated.root \
$refdir/performance_ckf_tracks_truth_estimated.root \
--title "CKF truth estimated" \
-o $outdir/ckf_truth_estimated.html \

run \
physmon/performance_ckf_tracks_seeded.root \
$outdir/performance_ckf_tracks_seeded.root \
$refdir/performance_ckf_tracks_seeded.root \
--title "CKF seeded" \
-o $outdir/ckf_seeded.html \

run \
physmon/performance_truth_tracking.root \
$outdir/performance_truth_tracking.root \
$refdir/performance_truth_tracking.root \
--title "Truth tracking" \
-c CI/physmon/truth_tracking.yml \
Expand Down
108 changes: 107 additions & 1 deletion Examples/Python/python/acts/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import inspect
import sys, inspect

from acts.ActsPythonBindings._examples import *
from acts import ActsPythonBindings
Expand Down Expand Up @@ -123,3 +123,109 @@ def _process_volume_intervals(kwargs):


_patchKwargsConstructor(TGeoDetector.Config.Volume, proc=_process_volume_intervals)


def NamedTypeArgs(**namedTypeArgs):
"""Decorator to move args of a named type (eg. `namedtuple` or `Enum`) to kwargs based on type, so user doesn't need to specify the key name.
Also allows the keyword argument to be converted from a built-in type (eg. `tuple` or `int`)."""

namedTypeClasses = {c: a for a, c in namedTypeArgs.items()}

def NamedTypeArgsDecorator(func):
from functools import wraps

@wraps(func)
def NamedTypeArgsWrapper(*args, **kwargs):
from collections.abc import Iterable

for k, v in kwargs.items():
cls = namedTypeArgs.get(k)
if cls is not None and v.__class__.__module__ == int.__module__:
if issubclass(cls, Iterable):
kwargs[k] = cls(*v)
else:
kwargs[k] = cls(v)

newargs = []
for a in args:
k = namedTypeClasses.get(type(a))
if k is None:
newargs.append(a)
elif k in kwargs:
raise KeyError(k)
else:
kwargs[k] = a
return func(*newargs, **kwargs)

return NamedTypeArgsWrapper

return NamedTypeArgsDecorator


def defaultKWArgs(**kwargs) -> dict:
"""Removes keyword arguments that are None or a list of all None (eg. [None,None]).
This keeps the called function's defaults."""
from collections.abc import Iterable

return {
k: v
for k, v in kwargs.items()
if not (
v is None or (isinstance(v, Iterable) and all([vv is None for vv in v]))
)
}


def dump_args(func):
"""
Decorator to print function call details.
This includes parameters names and effective values.
https://stackoverflow.com/questions/6200270/decorator-that-prints-function-call-details-parameters-names-and-effective-valu
"""
from functools import wraps

@wraps(func)
def dump_args_wrapper(*args, **kwargs):
import inspect

try:
func_args = inspect.signature(func).bind(*args, **kwargs).arguments
func_args_str = ", ".join(
map("{0[0]} = {0[1]!r}".format, func_args.items())
)
except ValueError:
func_args_str = ", ".join(
list(map("{0!r}".format, args))
+ list(map("{0[0]} = {0[1]!r}".format, kwargs.items()))
)
print(f"{func.__module__}.{func.__qualname__} ( {func_args_str} )")
return func(*args, **kwargs)

return dump_args_wrapper


def dump_args_calls(
myLocal=None,
mod=sys.modules[__name__],
):
"""
Wrap all calls to acts.examples Python bindings in dump_args.
Specify myLocal=locals() to include imported symbols too.
"""
import collections

for n in dir(mod):
if n.startswith("_") or n == "Config":
continue
f = getattr(mod, n)
if not (
isinstance(f, collections.abc.Callable)
and f.__module__.startswith("acts.ActsPythonBindings")
and not hasattr(f, "__wrapped__")
):
continue
dump_args_calls(myLocal, f) # wrap class's contained methods
w = dump_args(f)
setattr(mod, n, w)
if myLocal and hasattr(myLocal, n):
setattr(myLocal, n, w)
5 changes: 5 additions & 0 deletions Examples/Python/tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from acts.examples import BareAlgorithm

geant4Enabled = any(v.startswith("G4") for v in os.environ.keys())
if geant4Enabled:
try:
import acts.examples.geant4
except ImportError:
geant4Enabled = False
timadye marked this conversation as resolved.
Show resolved Hide resolved

try:
import ROOT
Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/tests/root_file_hashes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_fatras__fatras_particles_initial.root: 712a41d95ed1fccafccf708afddcd2177793
test_fatras__hits.root: f890599a8c94bc80270636c64039f8a0a7d8ddd716a15306d5ca61f15f8da5e8
test_seeding__estimatedparams.root: 50e281ec30150bdd13635dcbc0a1191be26a189a9ffd5cf1103307a62e6c9e47
test_seeding__performance_seeding_trees.root: c900a70a9881ce637a73ff730de4b2f4b6c0446854d666f70c7fc9c44c893666
test_seeding__evgen_particles.root: 4943f152bfad6ca6302563b57e495599fad4fea43b8e0b41abe5b8de31b391bc
test_seeding__particles.root: 4943f152bfad6ca6302563b57e495599fad4fea43b8e0b41abe5b8de31b391bc
test_seeding__fatras_particles_final.root: 934e290545090fe87d177bf40a78cf9375420e854433c2ef5a6d408fb3744d9d
test_seeding__fatras_particles_initial.root: 4943f152bfad6ca6302563b57e495599fad4fea43b8e0b41abe5b8de31b391bc
test_propagation__propagation_steps.root: 2d9a86e1097b8f0a845f33b05830f6b9c78cdeaeeb01685753e8dc9b434c7f9d
Expand Down
16 changes: 8 additions & 8 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_seeding(tmp_path, trk_geo, field, assert_root_hash):
0,
),
(
"evgen_particles.root",
"particles.root",
"particles",
seq.config.events,
),
Expand Down Expand Up @@ -195,10 +195,9 @@ def test_seeding(tmp_path, trk_geo, field, assert_root_hash):
assert_entries(fp, tn, exp_entries)
assert_root_hash(fn, fp)

assert_csv_output(csv, "evgen_particles")
assert_csv_output(csv, "evgen_particles")
assert_csv_output(csv, "fatras_particles_final")
assert_csv_output(csv, "fatras_particles_initial")
assert_csv_output(csv, "particles")
assert_csv_output(csv, "particles_final")
assert_csv_output(csv, "particles_initial")


def test_propagation(tmp_path, trk_geo, field, seq, assert_root_hash):
Expand Down Expand Up @@ -923,7 +922,7 @@ def test_ckf_tracks_example_truth_smeared(tmp_path, assert_root_hash):

@pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep not set up")
@pytest.mark.slow
# @pytest.mark.filterwarnings("ignore::UserWarning")
@pytest.mark.filterwarnings("ignore::UserWarning")
timadye marked this conversation as resolved.
Show resolved Hide resolved
def test_vertex_fitting(tmp_path):
detector, trackingGeometry, decorators = getOpenDataDetector()

Expand All @@ -936,7 +935,7 @@ def test_vertex_fitting(tmp_path):
runVertexFitting(
field,
vertexFinder=VertexFinder.Truth,
outputDir=Path.cwd(),
outputDir=tmp_path,
s=s,
)

Expand Down Expand Up @@ -982,7 +981,8 @@ def test_vertex_fitting_reading(
trackingGeometry,
field,
digiConfigFile=Path(
"Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
Path(__file__).parent.parent.parent.parent
/ "Examples/Algorithms/Digitization/share/default-smearing-config-generic.json"
),
outputDir=tmp_path,
s=s2,
Expand Down
Loading