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

Add global Celeritas input definition #1562

Merged
merged 61 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b141f2f
WIP: add Celeritas input file definitions
sethrj Jan 5, 2025
f4c1541
Add `accel` conversion function
sethrj Jan 5, 2025
d5f0e3e
Minor to-do/fixes
sethrj Jan 5, 2025
326bf81
Move root step writer input to a separate file
sethrj Jan 6, 2025
3a988b1
Fix input conversion code
sethrj Jan 6, 2025
67d2a57
Initial API adapter
sethrj Jan 6, 2025
b5076ca
Fix run input adapter
sethrj Jan 6, 2025
24a6192
Initial PGO adapter
sethrj Jan 6, 2025
81ed43e
Second iteration
sethrj Jan 6, 2025
cf9e8e1
Third iteration
sethrj Jan 6, 2025
72786b3
Better than a bot
sethrj Jan 6, 2025
6ef4148
Old RunnerInput
sethrj Jan 6, 2025
af3e311
First attempt for run input
sethrj Jan 6, 2025
7b6cea1
Second attempt for run input
sethrj Jan 6, 2025
c450af1
Fixes and updates
sethrj Jan 6, 2025
5ba26c0
Fix build errors
sethrj Jan 6, 2025
6a6cc80
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 6, 2025
9b4e510
Fix windows failure
sethrj Jan 7, 2025
cd46d68
WIP: physics parameters
sethrj Jan 7, 2025
a8f9035
Add comments
sethrj Jan 8, 2025
9b09dbe
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 8, 2025
912f700
Sketch out additional physics and such
sethrj Jan 9, 2025
c667bf0
Sketch out import
sethrj Jan 11, 2025
d0a927c
Update runner input
sethrj Jan 11, 2025
8eaae78
Generate framework input from SetupOptions
sethrj Jan 11, 2025
69b9ae0
Complete building of input parameters
sethrj Jan 12, 2025
8a4fa91
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 12, 2025
c1c852f
Fix typo
sethrj Jan 12, 2025
287b923
Add documentation
sethrj Jan 13, 2025
cdcbba1
Move input
sethrj Jan 13, 2025
8fba844
Add more documentation
sethrj Jan 13, 2025
da2da97
Complete documentation
sethrj Jan 13, 2025
09c65fb
Fix types
sethrj Jan 13, 2025
5718b40
Restructure, download zotero references
sethrj Jan 13, 2025
bd28340
WIP: documentation stuff
sethrj Jan 13, 2025
07c74bc
Revert zotero citation changes
sethrj Jan 13, 2025
86df859
Attempt to fix errors
sethrj Jan 13, 2025
23a19cf
Rename environ to avoid windows errors
sethrj Jan 13, 2025
ad6dae0
Update reference
sethrj Jan 13, 2025
77eafdd
Merge remote-tracking branch 'upstream/develop'
sethrj Jan 16, 2025
04a1ee7
Add to-dos and a couple of minor parameters
sethrj Jan 16, 2025
554f1d3
Address review feedback and add documentation
sethrj Jan 17, 2025
fa698e2
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 17, 2025
100a976
fixup! Add to-dos and a couple of minor parameters
sethrj Jan 17, 2025
34d0fa4
Revert changes to doc
sethrj Jan 22, 2025
6b25084
Add small doc update
sethrj Jan 22, 2025
08b0d95
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 22, 2025
14aa92b
Address review feedback
sethrj Jan 22, 2025
eaac1dd
Make sync-stream optional
sethrj Jan 22, 2025
368b809
fixup! Revert changes to doc
sethrj Jan 22, 2025
fc572e4
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 22, 2025
aff4bc8
Reapply "Add problem import stuff"
sethrj Jan 22, 2025
b976584
fixup! Address review feedback
sethrj Jan 22, 2025
61680f3
Revert accidental changes
sethrj Jan 22, 2025
41798cd
Add docs, make secondaries optional
sethrj Jan 23, 2025
427dd11
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 23, 2025
e075c7e
Rename Tuning to Control and remove std::move
sethrj Jan 23, 2025
4fb5e05
Fix lingering 'tuning' usage
sethrj Jan 23, 2025
85c4f22
Fix lingering issues
sethrj Jan 23, 2025
cf09d2c
Fix tuning
sethrj Jan 24, 2025
e5c891f
Merge remote-tracking branch 'upstream/develop' into celer-inp
sethrj Jan 24, 2025
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
142 changes: 142 additions & 0 deletions app/celer-g4/RunInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
//---------------------------------------------------------------------------//
#include "RunInput.hh"

#include <fstream>

#include "corecel/io/EnumStringMapper.hh"
#include "corecel/io/Logger.hh"
#include "corecel/math/ArrayUtils.hh"
#include "celeritas/inp/Input.hh"
#include "accel/SharedParams.hh"

namespace celeritas
Expand Down Expand Up @@ -57,6 +62,143 @@ RunInput::operator bool() const
&& (step_diagnostic_bins > 0 || !step_diagnostic);
}

//---------------------------------------------------------------------------//
inp::Input to_input(RunInput const& run_input)
{
using namespace celeritas;

inp::Input result;

result.tuning.environ
= {run_input.environ.begin(), run_input.environ.end()};

// TODO: add option to enable/disable rather than checking device/env
if (celeritas::device())
{
inp::Device device;
device.stack_size = run_input.cuda_stack_size;
device.heap_size = run_input.cuda_heap_size;
device.default_stream = run_input.default_stream;
result.tuning.device = std::move(device);
}

// Problem definition
result.geometry_file = run_input.geometry_file;

if (!run_input.event_file.empty())
{
inp::ReadFileEvents events;
events.event_file = run_input.event_file;
result.events = std::move(events);
}
else if (run_input.primary_options)
{
inp::PrimaryGenerator generator;
generator = run_input.primary_options;
result.events = std::move(generator);
}

// Control options
{
inp::StateCapacity capacity;
capacity.tracks = run_input.num_track_slots;
capacity.initializers = run_input.initializer_capacity;
capacity.secondaries = static_cast<size_type>(
run_input.secondary_stack_factor * run_input.num_track_slots);
capacity.primaries = run_input.auto_flush;
result.tuning.capacity = std::move(capacity);
}

{
inp::TrackingLimits limits;
limits.steps = run_input.max_steps;
result.tracking.limits = std::move(limits);
}

result.tuning.track_order = [&] {
auto track_order = run_input.track_order;
if (track_order != TrackOrder::size_)
return track_order;

if (result.tuning.device)
{
// Device is activated: initializing by charge is more performant
return TrackOrder::init_charge;
}

// Device is not active: don't ort
return TrackOrder::none;
}();

// Field setup
if (run_input.field_type == "rzmap")
{
CELER_LOG_LOCAL(info)
<< "Loading RZMapField from " << run_input.field_file;
std::ifstream inp(run_input.field_file);
CELER_VALIDATE(inp,
<< "failed to open field map file at '"
<< run_input.field_file << "'");

// Read RZ map from file
RZMapFieldInput rzmap;
inp >> rzmap;

// Replace driver options with user options
rzmap.driver_options = run_input.field_options;

result.field = std::move(rzmap);
}
else if (run_input.field_type == "uniform")
{
inp::UniformField field;
field.strength = run_input.field;

auto field_val = norm(field.strength);
CELER_LOG_LOCAL(info)
<< "Using a uniform field " << field_val << " [T]";
if (field_val > 0)
{
field.driver_options = run_input.field_options;
result.field = std::move(field);
}
}
else
{
CELER_VALIDATE(
false, << "invalid field type '" << run_input.field_type << "'");
}

if (run_input.sd_type != SensitiveDetectorType::none)
{
// Activate Geant4 SD callbacks
result.scoring.sd.emplace();
}

// Diagnostics
auto& d = result.diagnostics;
d.output_file = run_input.output_file;
d.export_files.physics = run_input.physics_output_file;
d.export_files.offload = run_input.offload_output_file;
d.timers.action = run_input.action_times;

if (!run_input.slot_diagnostic_prefix.empty())
{
inp::SlotDiagnostic slot_diag;
slot_diag.basename = run_input.slot_diagnostic_prefix;
d.slot = std::move(slot_diag);
}

if (run_input.step_diagnostic)
{
inp::StepDiagnostic step;
step.bins = run_input.step_diagnostic_bins;
d.step = std::move(step);
}

return result;
}

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
8 changes: 8 additions & 0 deletions app/celer-g4/RunInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@

namespace celeritas
{
//---------------------------------------------------------------------------//
namespace inp
{
struct Input;
}

namespace app
{
//---------------------------------------------------------------------------//
Expand Down Expand Up @@ -121,6 +127,8 @@ struct RunInput
char const* to_cstring(PhysicsListSelection value);
char const* to_cstring(SensitiveDetectorType value);

inp::Input to_input(RunInput const& run_input);

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
166 changes: 166 additions & 0 deletions app/celer-sim/RunnerInput.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
//------------------------------- -*- C++ -*- -------------------------------//
// Copyright Celeritas contributors: see top-level COPYRIGHT file for details
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celer-sim/RunnerInput.cc
//---------------------------------------------------------------------------//
#include "RunnerInput.hh"

#include <limits>

#include "celeritas/field/FieldDriverOptions.hh"
#include "celeritas/inp/Input.hh"

#include "PrimaryGeneratorOptions.hh"

namespace celeritas
{
namespace app
{
//---------------------------------------------------------------------------//
inp::Input to_input(RunnerInput const& r)
{
inp::Input result;

// Geometry and event configurations
result.geometry_file = r.geometry_file;

if (!run_input.event_file.empty())
{
if (r.file_sampling_options)
{
inp::SampleFileEvents sfe;
sfe.num_events = r.file_sampling_options.num_events;
sfe.num_merged = r.file_sampling_options.num_merged;
sfe.event_file = r.event_file;
result.events = std::move(sfe);
}
else
{
inp::ReadFileEvents rfe;
rfe.event_file = r.event_file;
result.events = std::move(rfe);
}
}
else if (run_input.primary_options)
{
inp::PrimaryGenerator generator;
result.events = to_input(r.primary_options);
}

// Magnetic field
if (r.field == RunnerInput::no_field())
{
result.field = inp::NoField{};
}
else
{
inp::UniformField field;
field.strength = r.field;
field.driver_options = r.field_options;
result.field = field;
}

// Diagnostics
auto& d = result.diagnostics;
if (!r.mctruth_file.empty())
{
inp::McTruth mct;
mct.output_file = r.mctruth_file;
mct.filter = r.mctruth_filter;
d.mctruth = std::move(mct);
}
d.perfetto_file = r.tracing_file;
d.timers.action = r.action_times;
d.timers.step = r.write_step_times;
d.action = r.action_diagnostic;
if (!r.slot_diagnostic_prefix.empty())
{
inp::SlotDiagnostic slot_diag;
slot_diag.basename = r.slot_diagnostic_prefix;
d.slot = std::move(slot_diag);
}
if (r.step_diagnostic)
{
inp::StepDiagnostic step_diag;
step_diag.bins = r.step_diagnostic_bins;
d.step = std::move(step_diag);
}
d.step_counters = r.write_track_counts;

// Tuning
{
inp::StateCapacity capacity;
capacity.tracks = r.num_track_slots;
capacity.initializers = r.initializer_capacity;
capacity.secondaries = r.secondary_stack_factor * r.num_track_slots;

// TODO: replace "max" with # events during construction?
constexpr auto LimitsT
= numeric_limits<decltype(capacity.events)> capacity.events
= r.merge_events ? LimitsT::max() : 0;

result.tuning.capacity = capacity;
}

if (r.use_device)
{
inp::Device device;
device.stack_size = r.cuda_stack_size;
device.heap_size = r.cuda_heap_size;
device.default_stream = r.default_stream;
result.tuning.device = std::move(device);
}

result.tuning.warm_up = r.warm_up;

// Environment
result.tuning.environ = {r.environ.begin(), r.environ.end()};

// Physics
{
inp::EmPhysicsOptions em_options;
em_options.brem_combined = r.brem_combined;

// Spline energy loss order
CELER_VALIDATE(r.spline_eloss_order > 0 && r.spline_eloss_order <= 2,
"unsupported energy loss spline order "
<< r.spline_eloss_order);
em_options.eloss_spline = (r.spline_eloss_order == 2);

// Step limiter for charged particles
em_options.step_limit = r.step_limiter;

result.physics.em_options = std::move(em_options);
result.physics.physics_file = r.physics_file;
}

// Tracking
inp::TrackingLimits tracking_limits;
tracking_limits.steps = r.max_steps;
result.tracking.limits = tracking_limits;

// Optical options
if (r.optical)
{
inp::StateCapacity optical_capacity;
optical_capacity.tracks = r.optical.num_track_slots;
optical_capacity.initializers = r.optical.initializer_capacity;
optical_capacity.primaries = r.optical.auto_flush;
result.tuning.optical_capacity = std::move(optical_capacity);
}

// Simple calorimeter scoring
if (!r.simple_calo.empty())
{
inp::SimpleCalo calo;
calo.volumes = r.simple_calo;
result.scoring.simple_calo = std::move(calo);
}

return result;
}

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
8 changes: 3 additions & 5 deletions app/celer-sim/RunnerInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ namespace app
/*!
* Input for a single run.
*
* TODO for v1.0: unify these names, combine with celer-g4, separate into
* schemas for individual classes, ... ? and decide whether max_steps should be
* per track or total step iterations.
* DEPRECATED: `RunInput` will be used instead.
*/
struct RunnerInput
{
Expand All @@ -49,7 +47,7 @@ struct RunnerInput
explicit operator bool() const
{
return num_events > 0 && num_merged > 0;
};
}
};

struct OpticalOptions
Expand All @@ -65,7 +63,7 @@ struct RunnerInput
{
return num_track_slots > 0 && buffer_capacity > 0
&& initializer_capacity > 0 && auto_flush > 0;
};
}
};
static constexpr Real3 no_field() { return Real3{0, 0, 0}; }
static constexpr size_type unspecified{0};
Expand Down
Loading
Loading