-
Notifications
You must be signed in to change notification settings - Fork 284
feat: Add Mille Solver #5954
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
Open
goblirsc
wants to merge
13
commits into
acts-project:main
Choose a base branch
from
goblirsc:MG_MilleSolver
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Add Mille Solver #5954
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0cfded2
make Mille MT-safe
goblirsc b4cfe70
Mille up
goblirsc 9f3773c
Merge branch 'main' into MG_MilleThreading
goblirsc 4f8897e
Merge branch 'main' into MG_MilleThreading
goblirsc 48f6822
update devcontainer spack
goblirsc fa1651e
Merge branch 'main' into MG_MilleThreading
goblirsc fd24cb2
add Mille Solver and associated tests
goblirsc 22944e7
deps to 24.4
goblirsc 6354cf0
fix 'invalid child process work dir' unit test and implement clang-ti…
goblirsc da0a418
SonarQube recommendations
goblirsc 66bebd5
Merge branch 'main' into MG_MilleSolver
goblirsc 822e97e
improvements from initial review
goblirsc a0ca38f
remove non-portable POSIX construct
goblirsc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
Plugins/Mille/include/ActsPlugins/Mille/MillePedeError.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <system_error> | ||
| #include <type_traits> | ||
|
|
||
| namespace ActsPlugins::ActsToMille { | ||
| /// Error codes for Millepede run | ||
| /// @ingroup errors | ||
| enum class MillePedeError { | ||
| InstallationNotFound = 1, // no valid install found | ||
| SteeringNotFound = 2, // steering file not found | ||
| SolverCrash = 3, // solver crashed | ||
| InvalidSolution = 4, // solver finished but the solution is invalid | ||
| SolutionNotReadable = 5, // solution file could not be read | ||
| }; | ||
|
|
||
| /// @cond | ||
| /// Create error code from MillePedeError | ||
| /// @param e The error code enum value | ||
| /// @return Standard error code | ||
| std::error_code make_error_code(ActsToMille::MillePedeError e); | ||
| /// @endcond | ||
|
|
||
| } // namespace ActsPlugins::ActsToMille | ||
|
|
||
| namespace std { | ||
| // register with STL | ||
| template <> | ||
| struct is_error_code_enum<ActsPlugins::ActsToMille::MillePedeError> | ||
| : std::true_type {}; | ||
| } // namespace std |
107 changes: 107 additions & 0 deletions
107
Plugins/Mille/include/ActsPlugins/Mille/MillePedeSolver.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
| #include "Acts/Utilities/Logger.hpp" | ||
| #include "Acts/Utilities/Result.hpp" | ||
| #include "ActsPlugins/Mille/MillePedeError.hpp" | ||
|
|
||
| #include <filesystem> | ||
| #include <vector> | ||
|
|
||
| namespace ActsPlugins::ActsToMille { | ||
|
|
||
| /// class wrapping an external call to the 'pede' solver | ||
| /// program of the Millepede-II alignment toolkit. | ||
| class MillePedeSolver { | ||
| public: | ||
| /// @brief abstract summary of the exit codes returned by pede. | ||
| enum class mpExitStatus { | ||
| notFinishedOrCrashed, /// job is still running or crashed before exiting | ||
| nominalExit, /// nominal exit | ||
| tolerableWarnings, /// exit with tolerable warnings, considered ok | ||
| seriousWarnings, /// exit with serious warnings, should investigate | ||
| noSolution, /// exit without solution (usually: rank deficit) | ||
| aborted /// aborted due to errors | ||
| }; | ||
|
|
||
| /// @brief configuration for running pede. | ||
| /// Currently, most details are delegated to the steering file syntax. | ||
| struct Config { | ||
| std::string steeringFile = | ||
| "pedeSteerMaster.txt"; /// steering file with run options | ||
| std::filesystem::path workDir = ""; /// directory to run in | ||
| std::vector<std::string> extraOpts = {}; /// extra CLI options | ||
| std::string resFileName = | ||
| ""; /// destination for result file - if empty, keep original | ||
| std::string redirectStdout = ""; /// destination for the cout/cerr printout | ||
| /// from pede - if empty, send to parent | ||
| std::string logFileName = | ||
| ""; /// destination for the log file - if empty, keep original | ||
| std::string histoFileName = | ||
| ""; /// destination for the histogram file - if empty, keep original | ||
| std::string evFileName = | ||
| ""; /// destination for the eigenvector file - if empty, keep original | ||
| }; | ||
|
|
||
| /// @brief package the result of the alignment fit | ||
| struct mpResult { | ||
|
goblirsc marked this conversation as resolved.
Outdated
|
||
| int exitCode = -1; /// raw pede exit code | ||
| mpExitStatus exitStatus = | ||
| mpExitStatus::notFinishedOrCrashed; /// summary exit status | ||
| std::string exitMessage = ""; /// detailed exit message | ||
| std::filesystem::path resultsFile; /// file containing parameter results | ||
| std::filesystem::path logFile; /// log file | ||
| std::filesystem::path histoFile; /// file with validation histograms | ||
| std::filesystem::path evFile; /// file with eigenvectors | ||
| }; | ||
|
|
||
| /// @brief constructor - nothing to do as minimal internal state carried | ||
| explicit MillePedeSolver(Acts::Logging::Level level = Acts::Logging::INFO) | ||
| : m_logger(Acts::getDefaultLogger("MillePedeSolver", level)) {} | ||
|
|
||
| /// @brief Runs the solving. | ||
| /// Can take some time for large fits. | ||
| /// Will invoke pede, await the exit, and parse | ||
| /// the output. | ||
| /// @param cfg: The configuration to use | ||
| Acts::Result<mpResult> solve(const Config& cfg) const; | ||
|
|
||
| private: | ||
| /// @brief translation of the detailed pede code to a summary status | ||
| /// Will translate the range of ~30 possible MP exit codes to a simplified | ||
| /// enum value that gives a high-level summary of the status. | ||
| /// @param theExitCode: The integer exit code found in the millepede.end file | ||
| static mpExitStatus interpretExit(int theExitCode); | ||
|
|
||
| /// @brief Reads the `millepede.end` file and parses its content | ||
| /// @param mpend: The file to read, assumed that the user has checked for existence before | ||
| /// @return a tuple containing the original integer exit code, a simplified exit status enum, | ||
| /// and the additional status message emitted by pede. | ||
| std::tuple<int, mpExitStatus, std::string> readDetailedExit( | ||
| const std::filesystem::path& mpend) const; | ||
|
|
||
| /// @brief Utility method to check if an output exists, copy it if the user requested a relocation, | ||
| /// and returns the final resolved output location, which will be: | ||
| /// - if the output does not exist: empty path | ||
| /// - if the output does exist and was not relocated: original location | ||
| /// - if the output does exist, and was relocated: user-specified location | ||
| /// - if the output does exist, was requested for relocation but the copy | ||
| /// failed: original location | ||
| /// @param originalLoc: Original expected location of the file | ||
| /// @param userLoc: Desired final location of the file. If empty, no copy will be made. | ||
| std::filesystem::path copyIfRequested( | ||
| const std::filesystem::path& originalLoc, | ||
| const std::filesystem::path& userLoc) const; | ||
|
|
||
| std::unique_ptr<const Acts::Logger> m_logger; /// logger | ||
|
|
||
| /// Private access to the logger | ||
| const Acts::Logger& logger() const { return *m_logger; } | ||
| }; | ||
| } // namespace ActsPlugins::ActsToMille | ||
43 changes: 43 additions & 0 deletions
43
Plugins/Mille/include/ActsPlugins/Mille/detail/runChildProcess.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // This file is part of the ACTS project. | ||
| // | ||
| // Copyright (C) 2016 CERN for the benefit of the ACTS project | ||
| // | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| #pragma once | ||
|
|
||
| /// Helper to define a "simple" interface for running pede | ||
| /// as a child process, without bringing in additional | ||
| /// external dependencies. | ||
|
|
||
| #include <filesystem> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace ActsPlugins::ActsToMille { | ||
|
|
||
| enum class childProcessStatus { | ||
|
goblirsc marked this conversation as resolved.
Outdated
|
||
| ok = 0, | ||
| progNotFound = 1, | ||
| failedRedirectStdout = 2, | ||
| failedWorkDir = 3, | ||
| failedRun = 4, | ||
| unknownError = 5 | ||
|
goblirsc marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| /// @brief attempt to run a program as a child process. | ||
| /// @param program: Program name (search on PATH) | ||
| /// @param args: command line args | ||
| /// @param path: if not empty, redirect output to a file instead | ||
| /// of printing to the host stdout | ||
| /// @param runDir: If not empty, will run in the specified directory. | ||
| /// Should already exist (caller is responsible). | ||
| /// @return a pair with the call outcome and the return code (if any, else -1). | ||
| childProcessStatus runChildProcess( | ||
|
goblirsc marked this conversation as resolved.
Outdated
|
||
| const std::string& program, const std::vector<std::string>& args, | ||
| const std::filesystem::path& runDir = "", | ||
| const std::filesystem::path& output_dest = ""); | ||
|
goblirsc marked this conversation as resolved.
Outdated
|
||
|
|
||
| } // namespace ActsPlugins::ActsToMille | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.