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 all 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
3 changes: 1 addition & 2 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
. /etc/profile
echo "/opt/view/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
# NOTE: checkout must occur *after* setting up environment to use the right Git version
# NOTE: checkout must occur *after* setting up environment for git tags to work
# NOTE: depth must be enough to include the previous tag
- name: Check out Celeritas
uses: actions/checkout@v4
Expand All @@ -66,7 +66,6 @@ jobs:
- name: Configure Celeritas
run: |
git config --global --add safe.directory ${PWD}
git fetch --tags
ln -fs scripts/cmake-presets/ci-${{matrix.image}}.json CMakeUserPresets.json
cmake --preset=${CMAKE_PRESET}
- name: Build Celeritas
Expand Down
202 changes: 202 additions & 0 deletions app/celer-g4/RunInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,172 @@
//---------------------------------------------------------------------------//
#include "RunInput.hh"

#include <fstream>

#include "corecel/Config.hh"

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

namespace celeritas
{
namespace app
{
namespace
{
//---------------------------------------------------------------------------//
inp::System load_system(RunInput const& ri)
{
inp::System s;

if (celeritas::Device::num_devices())
{
inp::Device d;
d.stack_size = ri.cuda_stack_size;
d.heap_size = ri.cuda_heap_size;
s.device = std::move(d);
}

s.environment = {ri.environ.begin(), ri.environ.end()};

return s;
}

//---------------------------------------------------------------------------//
inp::Problem load_problem(RunInput const& ri)
{
inp::Problem p;

// Model definition
p.model.geometry = ri.geometry_file;

// Control
p.control.capacity = [&ri] {
inp::StateCapacity capacity;
capacity.tracks = ri.num_track_slots;
capacity.initializers = ri.initializer_capacity;
capacity.secondaries = static_cast<size_type>(ri.secondary_stack_factor
* ri.num_track_slots);
capacity.primaries = ri.auto_flush;
return capacity;
}();

if (celeritas::Device::num_devices())
{
inp::DeviceDebug dd;
dd.default_stream = ri.default_stream;
dd.sync_stream = ri.action_times;
p.control.device_debug = std::move(dd);
}

if (ri.track_order != TrackOrder::size_)
{
p.control.track_order = ri.track_order;
}

{
inp::TrackingLimits& limits = p.tracking.limits;
limits.steps = ri.max_steps;
}

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

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

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

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

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

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

{
// Diagnostics
auto& d = p.diagnostics;
d.output_file = ri.output_file;
d.export_files.physics = ri.physics_output_file;
d.export_files.offload = ri.offload_output_file;
d.timers.action = ri.action_times;

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

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

CELER_VALIDATE(ri.macro_file.empty(),
<< "macro file is no longer supported");

return p;
}

//---------------------------------------------------------------------------//
inp::Events load_events(RunInput const& ri)
{
CELER_VALIDATE(ri.event_file.empty() != !ri.primary_options,
<< "either a event filename or options to generate "
"primaries must be provided (but not both)");

if (!ri.event_file.empty())
{
inp::ReadFileEvents rfe;
rfe.event_file = ri.event_file;
return rfe;
}

CELER_ASSERT(ri.primary_options);
return to_input(ri.primary_options);
}

//---------------------------------------------------------------------------//
} // namespace

//---------------------------------------------------------------------------//
/*!
* Get a string corresponding to the physics list selection.
Expand Down Expand Up @@ -57,6 +216,49 @@ RunInput::operator bool() const
&& (step_diagnostic_bins > 0 || !step_diagnostic);
}

//---------------------------------------------------------------------------//
/*!
* Convert to standalone input format.
*/
inp::StandaloneInput to_input(RunInput const& ri)
{
inp::StandaloneInput si;

si.system = load_system(ri);
si.problem = load_problem(ri);

// Set up Geant4
if (ri.physics_list == PhysicsListSelection::celer_ftfp_bert)
{
// Build hadronic physics
std::get<inp::Problem>(si.problem).physics.hadronic.emplace();
}
else
{
CELER_VALIDATE(ri.physics_list == PhysicsListSelection::celer_em,
<< "invalid physics list selection '"
<< to_cstring(ri.physics_list) << "' (must be 'celer')");
}

si.geant_setup = ri.physics_options;

inp::GeantImport geant_import;
geant_import.ignore_processes.push_back("CoulombScat");
if (CELERITAS_GEANT4_VERSION >= 0x0b0100)
{
CELER_LOG(warning) << "Default Rayleigh scattering 'MinKinEnergyPrim' "
"is not compatible between Celeritas and "
"[email protected]: disabling Rayleigh scattering";
geant_import.ignore_processes.push_back("Rayl");
}
si.physics_import = std::move(geant_import);

si.geant_data = inp::GeantDataImport{};
si.events = load_events(ri);

return si;
}

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
26 changes: 17 additions & 9 deletions app/celer-g4/RunInput.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@

namespace celeritas
{
namespace app
{
//---------------------------------------------------------------------------//
//! Physics list selection
enum class PhysicsListSelection
namespace inp
{
ftfp_bert,
celer_ftfp_bert, //!< FTFP BERT with Celeritas EM standard physics
celer_em, //!< Celeritas EM standard physics only
size_,
};
struct StandaloneInput;
}

namespace app
{
//---------------------------------------------------------------------------//
//! Sensitive detector capability
enum class SensitiveDetectorType
Expand All @@ -47,6 +43,16 @@ enum class SensitiveDetectorType
size_,
};

//---------------------------------------------------------------------------//
//! Physics list selection (TODO: remove)
enum class PhysicsListSelection
{
ftfp_bert,
celer_ftfp_bert, //!< FTFP BERT with Celeritas EM standard physics
celer_em, //!< Celeritas EM standard physics only
size_,
};

//---------------------------------------------------------------------------//
/*!
* Input for a single run.
Expand Down Expand Up @@ -121,6 +127,8 @@ struct RunInput
char const* to_cstring(PhysicsListSelection value);
char const* to_cstring(SensitiveDetectorType value);

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

//---------------------------------------------------------------------------//
} // namespace app
} // namespace celeritas
1 change: 1 addition & 0 deletions app/celer-sim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(SOURCES
celer-sim.cc
Runner.cc
RunnerOutput.cc
RunnerInput.cc
RunnerInputIO.json.cc
Transporter.cc
)
Expand Down
Loading
Loading