Skip to content

Commit

Permalink
refactor: Remove autodiff (acts-project#2793)
Browse files Browse the repository at this point in the history
related issues (closes acts-project#2792)
- acts-project#2792

`autodiff` became more of a burden at some point. Since we do not consistently template all the quantities we might want to derive later this became more of an exception. I propose to remove it for now until we have a broader solution or purpose for it
  • Loading branch information
andiwand authored Feb 6, 2024
1 parent 3a9c0bf commit c2e1e6e
Show file tree
Hide file tree
Showing 27 changed files with 707 additions and 1,731 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ linux_ubuntu_2204_clang:
-DACTS_BUILD_PLUGIN_JSON=ON
-DACTS_BUILD_FATRAS=ON
-DACTS_BUILD_PLUGIN_LEGACY=ON
-DACTS_BUILD_PLUGIN_AUTODIFF=OFF
-DACTS_BUILD_EXAMPLES_DD4HEP=OFF
-DACTS_BUILD_PLUGIN_EDM4HEP=OFF
-DACTS_BUILD_EXAMPLES_GEANT4=ON
Expand Down
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ option(ACTS_FORCE_ASSERTIONS "Force assertions regardless of build type" OFF)
# external library options
option(ACTS_USE_SYSTEM_LIBS "Use system libraries by default" OFF)
# plugins related options
option(ACTS_BUILD_PLUGIN_AUTODIFF "Build the autodiff plugin" OFF)
option(ACTS_USE_SYSTEM_AUTODIFF "Use autodiff provided by the system instead of the bundled version" ${ACTS_USE_SYSTEM_LIBS})
option(ACTS_USE_SYSTEM_ACTSVG "Use the ActSVG system library" ${ACTS_USE_SYSTEM_LIBS})
option(ACTS_BUILD_PLUGIN_ACTSVG "Build SVG display plugin" OFF)
option(ACTS_BUILD_PLUGIN_CUDA "Build CUDA plugin" OFF)
Expand Down Expand Up @@ -147,7 +145,6 @@ set_option_if(
ACTS_BUILD_FATRAS
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_LEGACY ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_AUTODIFF ACTS_BUILD_EVERYTHING)
set_option_if(ACTS_BUILD_PLUGIN_EXATRKX ACTS_BUILD_EXAMPLES_EXATRKX)
set_option_if(ACTS_BUILD_PLUGIN_FPEMON
ACTS_BUILD_EXAMPLES OR ACTS_BUILD_EVERYTHING)
Expand Down Expand Up @@ -283,14 +280,6 @@ if(ACTS_BUILD_PLUGIN_ACTSVG)
add_subdirectory(thirdparty/actsvg)
endif()
endif()
if(ACTS_BUILD_PLUGIN_AUTODIFF)
if(ACTS_USE_SYSTEM_AUTODIFF)
find_package(autodiff ${_acts_autodiff_version} CONFIG REQUIRED)
message(STATUS "Using system installation of autodiff")
else()
add_subdirectory(thirdparty/autodiff)
endif()
endif()
if(ACTS_BUILD_PLUGIN_CUDA)
enable_cuda()
endif()
Expand Down
71 changes: 24 additions & 47 deletions Core/include/Acts/EventData/Charge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "Acts/Definitions/Algebra.hpp"
#include "Acts/Definitions/Units.hpp"
#include "Acts/EventData/ChargeConcept.hpp"
#include "Acts/Utilities/Concepts.hpp"
Expand Down Expand Up @@ -67,19 +68,17 @@ struct Neutral {

constexpr float absQ() const noexcept { return 0; }

template <typename T>
constexpr auto extractCharge(T /*qOverP*/) const noexcept {
constexpr float extractCharge(ActsScalar /*qOverP*/) const noexcept {
return 0.0f;
}

template <typename T>
constexpr auto extractMomentum(T qOverP) const noexcept {
constexpr ActsScalar extractMomentum(ActsScalar qOverP) const noexcept {
assert(qOverP >= 0 && "qOverP cannot be negative");
return 1.0f / qOverP;
}

template <typename P, typename Q>
constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
constexpr ActsScalar qOverP(ActsScalar momentum,
float signedQ) const noexcept {
assert((signedQ != 0) && "charge must be 0");
(void)signedQ;
return 1.0f / momentum;
Expand Down Expand Up @@ -112,24 +111,18 @@ struct SinglyCharged {

constexpr float absQ() const noexcept { return UnitConstants::e; }

template <typename T>
constexpr auto extractCharge(T qOverP) const noexcept {
// using because of autodiff
using std::copysign;
return copysign(UnitConstants::e, qOverP);
constexpr float extractCharge(ActsScalar qOverP) const noexcept {
return std::copysign(UnitConstants::e, qOverP);
}

template <typename T>
constexpr auto extractMomentum(T qOverP) const noexcept {
// using because of autodiff
using std::abs;
constexpr ActsScalar extractMomentum(ActsScalar qOverP) const noexcept {
return extractCharge(qOverP) / qOverP;
}

template <typename P, typename Q>
constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
using std::abs;
assert((abs(signedQ) == UnitConstants::e) && "absolute charge must be e");
constexpr ActsScalar qOverP(ActsScalar momentum,
float signedQ) const noexcept {
assert((std::abs(signedQ) == UnitConstants::e) &&
"absolute charge must be e");
return signedQ / momentum;
}

Expand Down Expand Up @@ -158,24 +151,16 @@ class NonNeutralCharge {

constexpr float absQ() const noexcept { return m_absQ; }

template <typename T>
constexpr auto extractCharge(T qOverP) const noexcept {
// using because of autodiff
using std::copysign;
return copysign(m_absQ, qOverP);
constexpr float extractCharge(ActsScalar qOverP) const noexcept {
return std::copysign(m_absQ, qOverP);
}
template <typename T>
constexpr auto extractMomentum(T qOverP) const noexcept {
// using because of autodiff
using std::abs;
constexpr ActsScalar extractMomentum(ActsScalar qOverP) const noexcept {
return extractCharge(qOverP) / qOverP;
}

template <typename P, typename Q>
constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
// using because of autodiff
using std::abs;
assert(abs(signedQ) == m_absQ && "inconsistent charge");
constexpr ActsScalar qOverP(ActsScalar momentum,
float signedQ) const noexcept {
assert(std::abs(signedQ) == m_absQ && "inconsistent charge");
return signedQ / momentum;
}

Expand Down Expand Up @@ -208,24 +193,16 @@ class AnyCharge {

constexpr float absQ() const noexcept { return m_absQ; }

template <typename T>
constexpr auto extractCharge(T qOverP) const noexcept {
// using because of autodiff
using std::copysign;
return copysign(m_absQ, qOverP);
constexpr float extractCharge(ActsScalar qOverP) const noexcept {
return std::copysign(m_absQ, qOverP);
}
template <typename T>
constexpr auto extractMomentum(T qOverP) const noexcept {
// using because of autodiff
using std::abs;
constexpr ActsScalar extractMomentum(ActsScalar qOverP) const noexcept {
return (m_absQ != 0.0f) ? extractCharge(qOverP) / qOverP : 1.0f / qOverP;
}

template <typename P, typename Q>
constexpr auto qOverP(P momentum, Q signedQ) const noexcept {
// using because of autodiff
using std::abs;
assert(abs(signedQ) == m_absQ && "inconsistent charge");
constexpr ActsScalar qOverP(ActsScalar momentum,
float signedQ) const noexcept {
assert(std::abs(signedQ) == m_absQ && "inconsistent charge");
return (m_absQ != 0.0f) ? signedQ / momentum : 1.0f / momentum;
}

Expand Down
15 changes: 5 additions & 10 deletions Core/include/Acts/EventData/ChargeConcept.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ namespace Acts {
template <typename C>
concept ChargeConcept = requires(C c, float f, double d) {
{C{f}};
{ c.absQ() } -> std::same_as<float>;

{ c.extractCharge(f) } -> std::convertible_to<float>;
{ c.extractCharge(d) } -> std::convertible_to<float>;

{ c.extractMomentum(f) } -> std::convertible_to<float>;
{ c.extractMomentum(d) } -> std::convertible_to<float>;

{ c.qOverP(f, f) } -> std::same_as<float>;
{ c.qOverP(d, d) } -> std::same_as<double>;

{ c == c } -> std::same_as<bool>;
{ c != c } -> std::same_as<bool>;

{ c.absQ() } -> std::same_as<float>;
{ c.extractCharge(d) } -> std::same_as<float>;
{ c.extractMomentum(d) } -> std::same_as<double>;
{ c.qOverP(d, d) } -> std::same_as<double>;
};

} // namespace Acts
Expand Down
Loading

0 comments on commit c2e1e6e

Please sign in to comment.