From 93224a22891d264ff2e60d55b25408c1ad2afd84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Mon, 8 Jul 2024 16:31:17 +0200 Subject: [PATCH 1/6] Introduce identifier editing for recorded tapes. --- .../tapes/interfaces/editingTapeInterface.hpp | 5 +++ include/codi/tapes/jacobianReuseTape.hpp | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/codi/tapes/interfaces/editingTapeInterface.hpp b/include/codi/tapes/interfaces/editingTapeInterface.hpp index 0cfba8df..6d838391 100644 --- a/include/codi/tapes/interfaces/editingTapeInterface.hpp +++ b/include/codi/tapes/interfaces/editingTapeInterface.hpp @@ -82,5 +82,10 @@ namespace codi { /// Copy the specified range of the source tape and append it to the end of this tape. It has to hold /// start <= end. void append(EditingTapeInterface& source, Position const& start, Position const& end); + + /// @brief Modify the identifiers in an already recorded tape. + /// @tparam Func Callable void(Identifier&) for editing one identifier at a time. + template + void editIdentifiers(Func&& modifyIdentifier, Position const& start, Position const& end); }; } diff --git a/include/codi/tapes/jacobianReuseTape.hpp b/include/codi/tapes/jacobianReuseTape.hpp index 8b146a41..02ab285f 100644 --- a/include/codi/tapes/jacobianReuseTape.hpp +++ b/include/codi/tapes/jacobianReuseTape.hpp @@ -268,6 +268,41 @@ namespace codi { srcTape.llfByteData.evaluateForward(start, end, JacobianReuseTape::internalAppend, this); } + /// \copydoc codi::EditingTapeInterface::editIdentifiers + template + void editIdentifiers(Func&& modifyIdentifier, Position const& start, Position const& end) { + + auto evalFunc = [&modifyIdentifier]( + /* data from low level function byte data vector */ + size_t&, size_t const&, char*, + /* data from low level function info data vector */ + size_t&, size_t const&, Config::LowLevelFunctionToken* const, + Config::LowLevelFunctionDataSize* const, + /* data from jacobianData */ + size_t& curJacobianPos, size_t const&, Real const* const, Identifier* const rhsIdentifiers, + /* data from statementData */ + size_t& curStmtPos, size_t const& endStmtPos, Identifier* const lhsIdentifiers, + Config::ArgumentSize const* const numberOfJacobians) { + while (curStmtPos < endStmtPos) CODI_Likely { + Config::ArgumentSize const argsSize = numberOfJacobians[curStmtPos]; + + if (Config::StatementLowLevelFunctionTag != argsSize) CODI_Likely { // skip low-level functions + modifyIdentifier(lhsIdentifiers[curStmtPos]); + + size_t endJacobianPos = curJacobianPos + argsSize; + while (curJacobianPos < endJacobianPos) CODI_Likely { + modifyIdentifier(rhsIdentifiers[curJacobianPos]); + curJacobianPos += 1; + } + } + + curStmtPos += 1; + } + }; + + Base::llfByteData.evaluateForward(start, end, evalFunc); + } + /// @} private: From 534662fb884f47102f2c3f4cf5cbd7833c6163ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Tue, 9 Jul 2024 17:00:48 +0200 Subject: [PATCH 2/6] Tape traits to indicate support for tape editing. --- include/codi/traits/tapeTraits.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/codi/traits/tapeTraits.hpp b/include/codi/traits/tapeTraits.hpp index 29546a40..b8f4047f 100644 --- a/include/codi/traits/tapeTraits.hpp +++ b/include/codi/traits/tapeTraits.hpp @@ -38,6 +38,7 @@ #include "../config.h" #include "../misc/macros.hpp" +#include "../tapes/interfaces/editingTapeInterface.hpp" #include "../tapes/jacobianBaseTape.hpp" #include "../tapes/primalValueBaseTape.hpp" @@ -155,6 +156,30 @@ namespace codi { template using EnableIfReverseTape = typename std::enable_if::value>::type; + template + struct SupportsEditing : std::false_type {}; + +#ifndef DOXYGEN_DISABLE + template + struct SupportsEditing, Tape>::type> + : std::true_type {}; +#endif + +#if CODI_IS_CPP14 + /// Value entry of SupportsEditing + template + bool constexpr supportsEditing = SupportsEditing::value; +#endif + + /// Enable if wrapper for SupportsEditing + template + using EnableIfSupportsEditing = typename std::enable_if::value>::type; + + /// Enable if wrapper for SupportsEditing + template + using EnableIfNoEditing = typename std::enable_if::value>::type; + /// @} } } From 39db090843dd0054d0d861040f13d40180cf24ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Tue, 9 Jul 2024 18:23:27 +0200 Subject: [PATCH 3/6] Preaccumulation on local adjoints with prior tape editing. --- .../tools/helpers/preaccumulationHelper.hpp | 150 +++++++++++++++++- 1 file changed, 146 insertions(+), 4 deletions(-) diff --git a/include/codi/tools/helpers/preaccumulationHelper.hpp b/include/codi/tools/helpers/preaccumulationHelper.hpp index e25cde58..1bf9fbcd 100644 --- a/include/codi/tools/helpers/preaccumulationHelper.hpp +++ b/include/codi/tools/helpers/preaccumulationHelper.hpp @@ -146,6 +146,8 @@ namespace codi { } /// Finish the preaccumulation region and perform the preaccumulation. See `addOutput()` for outputs. + /// Not compatible with simultaneous thread-local preaccumulations with shared inputs. In this case, see + /// finishLocalMappedAdjoints, finishLocalAdjointsPreprocessTape, and finishLocalAdjoints. template void finish(bool const storeAdjoints, Outputs&... outputs) { Tape& tape = Type::getTape(); @@ -170,8 +172,47 @@ namespace codi { EventSystem::notifyPreaccFinishListeners(tape); } - /// Finish the preaccumulation region and perform the preaccumulation. Creates adjoints locally instead of using - /// adjoints from the tape. See `addOutput()` for outputs. + /// Finish the preaccumulation region and perform the preaccumulation. Creates a local map of adjoints instead of + /// using adjoints from the tape. See `addOutput()` for outputs. + template + void finishLocalMappedAdjoints(Outputs&... outputs) { + Tape& tape = Type::getTape(); + + if (tape.isActive()) { + addOutputRecursive(outputs...); + + tape.setPassive(); + computeJacobianLocalMappedAdjoints(); + storeJacobian(); + tape.setActive(); + } + + EventSystem::notifyPreaccFinishListeners(tape); + } + + /// Finish the preaccumulation region and perform the preaccumulation. Create a local adjoint vector instead of + /// using adjoints from the tape. Edits the tape, remapping the identifiers to a contiguous range. + /// More efficient than finishLocalMappedAdjoints if both the numbers of inputs and outputs are > 1. Behaves like + /// finishLocalMappedAdjoints if the underlying tape does not support editing. + template + void finishLocalAdjointsPreprocessTape(Outputs&... outputs) { + Tape& tape = Type::getTape(); + + if (tape.isActive()) { + addOutputRecursive(outputs...); + + tape.setPassive(); + computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise computeJacobianLocalMappedAdjoints + storeJacobian(); + tape.setActive(); + } + + EventSystem::notifyPreaccFinishListeners(tape); + } + + /// Finish the preaccumulation region and perform the preaccumulation. Uses local adjoints instead of adjoints + /// from the tape. Forwards to finishLocalMappedAdjoints or finishLocalAdjointsPreprocessTape, depending on which + /// is more efficient given the numbers of inputs and outputs. See `addOutput()` for outputs. template void finishLocalAdjoints(Outputs&... outputs) { Tape& tape = Type::getTape(); @@ -180,7 +221,12 @@ namespace codi { addOutputRecursive(outputs...); tape.setPassive(); - computeJacobianLocalAdjoints(); + if (std::min(inputData.size(), outputData.size()) > 1) { + computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise computeJacobianLocalMappedAdjoints + } else { + computeJacobianLocalMappedAdjoints(); + } + storeJacobian(); tape.setActive(); } @@ -190,6 +236,18 @@ namespace codi { private: + // Tape supports editing -> use a map to edit its identifiers. Disabled by SFINAE otherwise. + template + TapeTraits::EnableIfSupportsEditing computeJacobianLocalAdjointsPreprocessTapeIfAvailable() { + computeJacobianLocalAdjointsPreprocessTape(); + } + + // Tape does not support editing -> use a map for the adjoints. Disabled by SFINAE otherwise. + template + TapeTraits::EnableIfNoEditing computeJacobianLocalAdjointsPreprocessTapeIfAvailable() { + computeJacobianLocalMappedAdjoints(); + } + void addInputLogic(Type const& input) { EventSystem::notifyPreaccAddInputListeners(Type::getTape(), input.getValue(), input.getIdentifier()); Identifier const& identifier = input.getIdentifier(); @@ -279,7 +337,7 @@ namespace codi { tape.endUseAdjointVector(); } - void computeJacobianLocalAdjoints() { + void computeJacobianLocalMappedAdjoints() { // Perform the accumulation of the tape part. Tape& tape = Type::getTape(); Position endPos = tape.getPosition(); @@ -297,6 +355,64 @@ namespace codi { tape.resetTo(startPos, false); } + void computeJacobianLocalAdjointsPreprocessTape() { + // Perform the accumulation of the tape part. + Tape& tape = Type::getTape(); + Position endPos = tape.getPosition(); + + resizeJacobian(); + + // Used internally for remapping identifiers. + using IdentifierMap = std::map; + + // Build a map of identifiers, remapping identifiers in the recording to contiguous ones. + auto nextIdentifier = typename Tape::Identifier() + 1; + IdentifierMap oldToNewIdentifierMap; + + auto addIdentifierToMapping = [&](typename Tape::Identifier const& oldIdentifier) { + if (tape.isIdentifierActive(oldIdentifier) && + oldToNewIdentifierMap.find(oldIdentifier) == oldToNewIdentifierMap.end()) { + oldToNewIdentifierMap[oldIdentifier] = nextIdentifier++; + } + }; + + // Begin by remapping input identifiers. + for (auto const& oldIdentifier : inputData) { + addIdentifierToMapping(oldIdentifier); + } + + auto addAndEditIdentifier = [&](typename Tape::Identifier& oldIdentifier) { + addIdentifierToMapping(oldIdentifier); + oldIdentifier = oldToNewIdentifierMap[oldIdentifier]; + }; + + // Process the recording to complete the map, edit the tape on the fly. + tape.template editIdentifiers(addAndEditIdentifier, startPos, endPos); + + // Build new vectors of input and output identifiers. + std::vector newInputData; + newInputData.reserve(inputData.size()); + for (auto const& identifier : inputData) { + newInputData.push_back(oldToNewIdentifierMap[identifier]); + } + + std::vector newOutputData; + newOutputData.reserve(outputData.size()); + for (auto const& identifier : outputData) { + newOutputData.push_back(oldToNewIdentifierMap[identifier]); + } + + // Create local adjoints. nextIdentifier holds the local adjoint vector size. + std::vector localAdjoints(nextIdentifier); + + // Preaccumulation with remapped identifiers on local adjoints. + Algorithms::computeJacobianCustomAdjoints(startPos, endPos, newInputData.data(), newInputData.size(), + newOutputData.data(), newOutputData.size(), jacobian, + localAdjoints.data()); + + tape.resetTo(startPos, false); + } + void storeJacobian() { Tape& tape = Type::getTape(); @@ -403,6 +519,20 @@ namespace codi { // Do nothing. } + /// Does nothing. + template + void finishLocalMappedAdjoints(Outputs&... outputs) { + CODI_UNUSED(outputs...); + // Do nothing. + } + + /// Does nothing. + template + void finishLocalAdjointsPreprocessTape(Outputs&... outputs) { + CODI_UNUSED(outputs...); + // Do nothing. + } + /// Does nothing. template void finishLocalAdjoints(Outputs&... outputs) { @@ -504,6 +634,18 @@ namespace codi { } } + /// Reverts the tags on all input and output values. + template + void finishLocalMappedAdjoints(Outputs&... outputs) { + finish(false, outputs...); + } + + /// Reverts the tags on all input and output values. + template + void finishLocalAdjointsPreprocessTape(Outputs&... outputs) { + finish(false, outputs...); + } + /// Reverts the tags on all input and output values. template void finishLocalAdjoints(Outputs&... outputs) { From 548b19e8f85119a1a8fc030a96fd63d9bcb22ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Tue, 9 Jul 2024 18:26:27 +0200 Subject: [PATCH 4/6] Tests for the new code paths. --- tests/general/Makefile.drivers | 2 +- tests/general/include/tests/allTests.hpp | 13 ++++ .../tools/helpers/basePreaccumulation.hpp | 70 +++++++++++++++++++ .../tools/helpers/testPreaccumulation.hpp | 28 +------- .../testPreaccumulationLocalAdjoints.hpp | 45 ++++++++++++ ...ccumulationLocalAdjointsPreprocessTape.hpp | 45 ++++++++++++ ...tionLocalAdjointsPreprocessTapeForward.hpp | 46 ++++++++++++ ...ntsPreprocessTapeForwardInvalidAdjoint.hpp | 46 ++++++++++++ ...alAdjointsPreprocessTapeLargeStatement.hpp | 46 ++++++++++++ ...ocalAdjointsPreprocessTapePassiveValue.hpp | 46 ++++++++++++ ...nLocalAdjointsPreprocessTapeZeroJacobi.hpp | 46 ++++++++++++ ...testPreaccumulationLocalMappedAdjoints.hpp | 45 ++++++++++++ ...accumulationLocalMappedAdjointsForward.hpp | 46 ++++++++++++ ...calMappedAdjointsForwardInvalidAdjoint.hpp | 46 ++++++++++++ ...ationLocalMappedAdjointsLargeStatement.hpp | 46 ++++++++++++ ...ulationLocalMappedAdjointsPassiveValue.hpp | 46 ++++++++++++ ...umulationLocalMappedAdjointsZeroJacobi.hpp | 46 ++++++++++++ ...ccumulationLocalAdjointsPreprocessTape.out | 3 + ...tionLocalAdjointsPreprocessTapeForward.out | 5 ++ ...ntsPreprocessTapeForwardInvalidAdjoint.out | 5 ++ ...alAdjointsPreprocessTapeLargeStatement.out | 3 + ...ocalAdjointsPreprocessTapePassiveValue.out | 3 + ...nLocalAdjointsPreprocessTapeZeroJacobi.out | 3 + .../PreaccumulationLocalMappedAdjoints.out | 3 + ...accumulationLocalMappedAdjointsForward.out | 5 ++ ...calMappedAdjointsForwardInvalidAdjoint.out | 5 ++ ...ationLocalMappedAdjointsLargeStatement.out | 3 + ...ulationLocalMappedAdjointsPassiveValue.out | 3 + ...umulationLocalMappedAdjointsZeroJacobi.out | 3 + ...ccumulationLocalAdjointsPreprocessTape.out | 4 ++ ...tionLocalAdjointsPreprocessTapeForward.out | 6 ++ ...ntsPreprocessTapeForwardInvalidAdjoint.out | 6 ++ ...alAdjointsPreprocessTapeLargeStatement.out | 4 ++ ...ocalAdjointsPreprocessTapePassiveValue.out | 4 ++ ...nLocalAdjointsPreprocessTapeZeroJacobi.out | 4 ++ .../PreaccumulationLocalMappedAdjoints.out | 4 ++ ...accumulationLocalMappedAdjointsForward.out | 6 ++ ...calMappedAdjointsForwardInvalidAdjoint.out | 6 ++ ...ationLocalMappedAdjointsLargeStatement.out | 4 ++ ...ulationLocalMappedAdjointsPassiveValue.out | 4 ++ ...umulationLocalMappedAdjointsZeroJacobi.out | 4 ++ ...ccumulationLocalAdjointsPreprocessTape.out | 9 +++ ...tionLocalAdjointsPreprocessTapeForward.out | 17 +++++ ...ntsPreprocessTapeForwardInvalidAdjoint.out | 17 +++++ ...alAdjointsPreprocessTapeLargeStatement.out | 9 +++ ...ocalAdjointsPreprocessTapePassiveValue.out | 9 +++ ...nLocalAdjointsPreprocessTapeZeroJacobi.out | 9 +++ .../PreaccumulationLocalMappedAdjoints.out | 9 +++ ...accumulationLocalMappedAdjointsForward.out | 17 +++++ ...calMappedAdjointsForwardInvalidAdjoint.out | 17 +++++ ...ationLocalMappedAdjointsLargeStatement.out | 9 +++ ...ulationLocalMappedAdjointsPassiveValue.out | 9 +++ ...umulationLocalMappedAdjointsZeroJacobi.out | 9 +++ 53 files changed, 922 insertions(+), 26 deletions(-) create mode 100644 tests/general/include/tests/tools/helpers/basePreaccumulation.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjoints.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForward.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeLargeStatement.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapePassiveValue.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjoints.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForward.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsLargeStatement.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsPassiveValue.hpp create mode 100644 tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsZeroJacobi.hpp create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTape.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForward.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjoints.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForward.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsLargeStatement.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsPassiveValue.out create mode 100644 tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsZeroJacobi.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTape.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForward.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjoints.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForward.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsLargeStatement.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsPassiveValue.out create mode 100644 tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsZeroJacobi.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTape.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForward.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjoints.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForward.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsLargeStatement.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsPassiveValue.out create mode 100644 tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsZeroJacobi.out diff --git a/tests/general/Makefile.drivers b/tests/general/Makefile.drivers index b0d1ce21..a46d489e 100644 --- a/tests/general/Makefile.drivers +++ b/tests/general/Makefile.drivers @@ -51,7 +51,7 @@ endef VECTOR_DIM = 5 # filter out tests that require variable adjoint interfaces in primal tapes -PRIMAL_TAPE_TESTS_NO_VAI = $(filter-out TestPreaccumulationLocalAdjoints%, $(ALL_TESTS)) +PRIMAL_TAPE_TESTS_NO_VAI = $(filter-out TestPreaccumulationLocalAdjoints% TestPreaccumulationLocalMappedAdjoints%, $(ALL_TESTS)) EH_JACOBI_TAPE_TESTS = $(filter-out TestReset, $(ALL_TESTS)) EH_PRIMAL_TAPE_TESTS = $(filter-out TestPreaccumulation% TestReset TestStatementPushHelper, $(ALL_TESTS)) diff --git a/tests/general/include/tests/allTests.hpp b/tests/general/include/tests/allTests.hpp index 4ff6b015..57bdf7ee 100644 --- a/tests/general/include/tests/allTests.hpp +++ b/tests/general/include/tests/allTests.hpp @@ -64,11 +64,24 @@ #include "tools/helpers/testPreaccumulationForward.hpp" #include "tools/helpers/testPreaccumulationForwardInvalidAdjoint.hpp" #include "tools/helpers/testPreaccumulationLargeStatement.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjoints.hpp" #include "tools/helpers/testPreaccumulationLocalAdjointsForward.hpp" #include "tools/helpers/testPreaccumulationLocalAdjointsForwardInvalidAdjoint.hpp" #include "tools/helpers/testPreaccumulationLocalAdjointsLargeStatement.hpp" #include "tools/helpers/testPreaccumulationLocalAdjointsPassiveValue.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForward.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeLargeStatement.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapePassiveValue.hpp" +#include "tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.hpp" #include "tools/helpers/testPreaccumulationLocalAdjointsZeroJacobi.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjoints.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjointsForward.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjointsLargeStatement.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjointsPassiveValue.hpp" +#include "tools/helpers/testPreaccumulationLocalMappedAdjointsZeroJacobi.hpp" #include "tools/helpers/testPreaccumulationPassiveValue.hpp" #include "tools/helpers/testPreaccumulationZeroJacobi.hpp" #include "tools/helpers/testReset.hpp" diff --git a/tests/general/include/tests/tools/helpers/basePreaccumulation.hpp b/tests/general/include/tests/tools/helpers/basePreaccumulation.hpp new file mode 100644 index 00000000..8bf0c70d --- /dev/null +++ b/tests/general/include/tests/tools/helpers/basePreaccumulation.hpp @@ -0,0 +1,70 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ + +#pragma once + +#include "../../../testInterface.hpp" + +template +struct BasePreaccumulation : public TestInterface { + public: + IN(2) + OUT(2) + POINTS(1) = {{1.0, 0.5}}; + + template + static void evalFunc(Number* x, Number* y) { + y[0] = x[0]; + y[1] = x[1]; + for (int i = 0; i < 5; ++i) { + Number xTemp = y[0]; + Number yTemp = y[1]; + + y[0] = xTemp * xTemp - yTemp * yTemp - 0.65; + y[1] = 2.0 * yTemp * xTemp; + } + } + + template + static void func(Number* x, Number* y) { + codi::PreaccumulationHelper ph; + + ph.start(x[0], x[1]); + + evalFunc(x, y); + + Impl::finish(ph, y); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulation.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulation.hpp index 85abf8a3..31128bdd 100644 --- a/tests/general/include/tests/tools/helpers/testPreaccumulation.hpp +++ b/tests/general/include/tests/tools/helpers/testPreaccumulation.hpp @@ -32,36 +32,14 @@ * - Former members: * - Tim Albring */ -#include "../../../testInterface.hpp" +#include "basePreaccumulation.hpp" -struct TestPreaccumulation : public TestInterface { +struct TestPreaccumulation : public BasePreaccumulation { public: NAME("Preaccumulation") - IN(2) - OUT(2) - POINTS(1) = {{1.0, 0.5}}; template - static void evalFunc(Number* x, Number* y) { - y[0] = x[0]; - y[1] = x[1]; - for (int i = 0; i < 5; ++i) { - Number xTemp = y[0]; - Number yTemp = y[1]; - - y[0] = xTemp * xTemp - yTemp * yTemp - 0.65; - y[1] = 2.0 * yTemp * xTemp; - } - } - - template - static void func(Number* x, Number* y) { - codi::PreaccumulationHelper ph; - - ph.start(x[0], x[1]); - - evalFunc(x, y); - + static void finish(codi::PreaccumulationHelper& ph, Number* y) { ph.finish(false, y[0], y[1]); } }; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjoints.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjoints.hpp new file mode 100644 index 00000000..fe837832 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjoints.hpp @@ -0,0 +1,45 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulation.hpp" + +struct TestPreaccumulationLocalAdjoints : public BasePreaccumulation { + public: + NAME("PreaccumulationLocalAdjoints") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjoints(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp new file mode 100644 index 00000000..be25da48 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp @@ -0,0 +1,45 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulation.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTape : public BasePreaccumulation { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTape") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjointsPreprocessTape(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForward.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForward.hpp new file mode 100644 index 00000000..d9b2c179 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForward.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationForward.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTapeForward + : public BasePreaccumulationForward { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTapeForward") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjointsPreprocessTape(y[0], y[1], y[2], y[3]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp new file mode 100644 index 00000000..003c4139 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationForwardInvalidAdjoint.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint + : public BasePreaccumulationForwardInvalidAdjoint { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjointsPreprocessTape(y[0], y[1], y[2], y[3]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeLargeStatement.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeLargeStatement.hpp new file mode 100644 index 00000000..0b98d776 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeLargeStatement.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationLargeStatement.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTapeLargeStatement + : public BasePreaccumulationLargeStatement { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTapeLargeStatement") + + template + static void finish(PreaccHelper& ph) { + ph.finishLocalAdjointsPreprocessTape(); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapePassiveValue.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapePassiveValue.hpp new file mode 100644 index 00000000..ad1070e2 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapePassiveValue.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationPassiveValue.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTapePassiveValue + : public BasePreaccumulationPassiveValue { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTapePassiveValue") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjointsPreprocessTape(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.hpp new file mode 100644 index 00000000..f99386fb --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationZeroJacobi.hpp" + +struct TestPreaccumulationLocalAdjointsPreprocessTapeZeroJacobi + : public BasePreaccumulationZeroJacobi { + public: + NAME("PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalAdjointsPreprocessTape(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjoints.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjoints.hpp new file mode 100644 index 00000000..68b5a687 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjoints.hpp @@ -0,0 +1,45 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulation.hpp" + +struct TestPreaccumulationLocalMappedAdjoints : public BasePreaccumulation { + public: + NAME("PreaccumulationLocalMappedAdjoints") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalMappedAdjoints(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForward.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForward.hpp new file mode 100644 index 00000000..7757a0cb --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForward.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationForward.hpp" + +struct TestPreaccumulationLocalMappedAdjointsForward + : public BasePreaccumulationForward { + public: + NAME("PreaccumulationLocalMappedAdjointsForward") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalMappedAdjoints(y[0], y[1], y[2], y[3]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.hpp new file mode 100644 index 00000000..3829fb97 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationForwardInvalidAdjoint.hpp" + +struct TestPreaccumulationLocalMappedAdjointsForwardInvalidAdjoint + : public BasePreaccumulationForwardInvalidAdjoint { + public: + NAME("PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalMappedAdjoints(y[0], y[1], y[2], y[3]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsLargeStatement.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsLargeStatement.hpp new file mode 100644 index 00000000..c0f3c9aa --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsLargeStatement.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationLargeStatement.hpp" + +struct TestPreaccumulationLocalMappedAdjointsLargeStatement + : public BasePreaccumulationLargeStatement { + public: + NAME("PreaccumulationLocalMappedAdjointsLargeStatement") + + template + static void finish(PreaccHelper& ph) { + ph.finishLocalMappedAdjoints(); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsPassiveValue.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsPassiveValue.hpp new file mode 100644 index 00000000..2077048d --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsPassiveValue.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationPassiveValue.hpp" + +struct TestPreaccumulationLocalMappedAdjointsPassiveValue + : public BasePreaccumulationPassiveValue { + public: + NAME("PreaccumulationLocalMappedAdjointsPassiveValue") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalMappedAdjoints(y[0], y[1]); + } +}; diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsZeroJacobi.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsZeroJacobi.hpp new file mode 100644 index 00000000..252cbbb4 --- /dev/null +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalMappedAdjointsZeroJacobi.hpp @@ -0,0 +1,46 @@ +/* + * CoDiPack, a Code Differentiation Package + * + * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau + * Homepage: http://www.scicomp.uni-kl.de + * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de) + * + * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau) + * + * This file is part of CoDiPack (http://www.scicomp.uni-kl.de/software/codi). + * + * CoDiPack is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * CoDiPack is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * See the GNU General Public License for more details. + * You should have received a copy of the GNU + * General Public License along with CoDiPack. + * If not, see . + * + * For other licensing options please contact us. + * + * Authors: + * - SciComp, University of Kaiserslautern-Landau: + * - Max Sagebaum + * - Johannes Blühdorn + * - Former members: + * - Tim Albring + */ +#include "basePreaccumulationZeroJacobi.hpp" + +struct TestPreaccumulationLocalMappedAdjointsZeroJacobi + : public BasePreaccumulationZeroJacobi { + public: + NAME("PreaccumulationLocalMappedAdjointsZeroJacobi") + + template + static void finish(codi::PreaccumulationHelper& ph, Number* y) { + ph.finishLocalMappedAdjoints(y[0], y[1]); + } +}; diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTape.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTape.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTape.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForward.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForward.out new file mode 100644 index 00000000..993623d8 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForward.out @@ -0,0 +1,5 @@ +Point 0 : {1.000000, 0.500000} + out_000 -nan + out_001 -nan + out_002 1 + out_003 0.25 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out new file mode 100644 index 00000000..72ad6fdd --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out @@ -0,0 +1,5 @@ +Point 0 : {1.000000, 0.500000} + out_000 3.125 + out_001 0 + out_002 2.44141 + out_003 1 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out new file mode 100644 index 00000000..1160aa96 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 294912 + out_001 767.5 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjoints.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjoints.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjoints.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForward.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForward.out new file mode 100644 index 00000000..993623d8 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForward.out @@ -0,0 +1,5 @@ +Point 0 : {1.000000, 0.500000} + out_000 -nan + out_001 -nan + out_002 1 + out_003 0.25 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out new file mode 100644 index 00000000..72ad6fdd --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out @@ -0,0 +1,5 @@ +Point 0 : {1.000000, 0.500000} + out_000 3.125 + out_001 0 + out_002 2.44141 + out_003 1 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsLargeStatement.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsLargeStatement.out new file mode 100644 index 00000000..1160aa96 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsLargeStatement.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 294912 + out_001 767.5 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsPassiveValue.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsPassiveValue.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsPassiveValue.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsZeroJacobi.out b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsZeroJacobi.out new file mode 100644 index 00000000..b3071481 --- /dev/null +++ b/tests/general/results/deriv0th/PreaccumulationLocalMappedAdjointsZeroJacobi.out @@ -0,0 +1,3 @@ +Point 0 : {1.000000, 0.500000} + out_000 0.982476 + out_001 -15.3109 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTape.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTape.out new file mode 100644 index 00000000..2efa6aa1 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTape.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 -354.168 339.417 + out_001 -339.417 -354.168 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForward.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForward.out new file mode 100644 index 00000000..51d8300f --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForward.out @@ -0,0 +1,6 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 0 + out_001 0 0 + out_002 2 0 + out_003 0 1 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out new file mode 100644 index 00000000..196a0b8b --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out @@ -0,0 +1,6 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 15.75 -10 + out_001 0 0 + out_002 24.6094 -15.625 + out_003 0 0 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out new file mode 100644 index 00000000..d3cd5f27 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 294528 768 + out_001 767 1 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out new file mode 100644 index 00000000..12a75e24 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 339.417 + out_001 0 -354.168 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out new file mode 100644 index 00000000..12a75e24 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 339.417 + out_001 0 -354.168 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjoints.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjoints.out new file mode 100644 index 00000000..2efa6aa1 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjoints.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 -354.168 339.417 + out_001 -339.417 -354.168 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForward.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForward.out new file mode 100644 index 00000000..51d8300f --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForward.out @@ -0,0 +1,6 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 0 + out_001 0 0 + out_002 2 0 + out_003 0 1 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out new file mode 100644 index 00000000..196a0b8b --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out @@ -0,0 +1,6 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 15.75 -10 + out_001 0 0 + out_002 24.6094 -15.625 + out_003 0 0 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsLargeStatement.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsLargeStatement.out new file mode 100644 index 00000000..d3cd5f27 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsLargeStatement.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 294528 768 + out_001 767 1 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsPassiveValue.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsPassiveValue.out new file mode 100644 index 00000000..12a75e24 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsPassiveValue.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 339.417 + out_001 0 -354.168 diff --git a/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsZeroJacobi.out b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsZeroJacobi.out new file mode 100644 index 00000000..12a75e24 --- /dev/null +++ b/tests/general/results/deriv1st/PreaccumulationLocalMappedAdjointsZeroJacobi.out @@ -0,0 +1,4 @@ +Point 0 : {1.000000, 0.500000} + in_000 in_001 + out_000 0 339.417 + out_001 0 -354.168 diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTape.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTape.out new file mode 100644 index 00000000..8b59c301 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTape.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 -13829.1 -2559.17 + in_001 -2559.17 13829.1 + + out_001 in_000 in_001 + in_000 2559.17 -13829.1 + in_001 -13829.1 -2559.17 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForward.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForward.out new file mode 100644 index 00000000..dd54ba5a --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForward.out @@ -0,0 +1,17 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_002 in_000 in_001 + in_000 2 0 + in_001 0 0 + + out_003 in_000 in_001 + in_000 0 0 + in_001 0 2 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out new file mode 100644 index 00000000..f9293c57 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.out @@ -0,0 +1,17 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 61.25 -61 + in_001 -61 150 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_002 in_000 in_001 + in_000 219.734 -174.062 + in_001 -174.062 284.375 + + out_003 in_000 in_001 + in_000 0 0 + in_001 0 -1.77636e-15 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out new file mode 100644 index 00000000..e19b04a3 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeLargeStatement.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out new file mode 100644 index 00000000..cf54d870 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapePassiveValue.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 13829.1 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 -2559.17 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out new file mode 100644 index 00000000..cf54d870 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalAdjointsPreprocessTapeZeroJacobi.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 13829.1 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 -2559.17 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjoints.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjoints.out new file mode 100644 index 00000000..8b59c301 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjoints.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 -13829.1 -2559.17 + in_001 -2559.17 13829.1 + + out_001 in_000 in_001 + in_000 2559.17 -13829.1 + in_001 -13829.1 -2559.17 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForward.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForward.out new file mode 100644 index 00000000..dd54ba5a --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForward.out @@ -0,0 +1,17 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_002 in_000 in_001 + in_000 2 0 + in_001 0 0 + + out_003 in_000 in_001 + in_000 0 0 + in_001 0 2 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out new file mode 100644 index 00000000..f9293c57 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsForwardInvalidAdjoint.out @@ -0,0 +1,17 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 61.25 -61 + in_001 -61 150 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_002 in_000 in_001 + in_000 219.734 -174.062 + in_001 -174.062 284.375 + + out_003 in_000 in_001 + in_000 0 0 + in_001 0 -1.77636e-15 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsLargeStatement.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsLargeStatement.out new file mode 100644 index 00000000..e19b04a3 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsLargeStatement.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 0 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 0 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsPassiveValue.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsPassiveValue.out new file mode 100644 index 00000000..cf54d870 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsPassiveValue.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 13829.1 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 -2559.17 + diff --git a/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsZeroJacobi.out b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsZeroJacobi.out new file mode 100644 index 00000000..cf54d870 --- /dev/null +++ b/tests/general/results/deriv2nd/PreaccumulationLocalMappedAdjointsZeroJacobi.out @@ -0,0 +1,9 @@ +Point 0 : {1.000000, 0.500000} + out_000 in_000 in_001 + in_000 0 0 + in_001 0 13829.1 + + out_001 in_000 in_001 + in_000 0 0 + in_001 0 -2559.17 + From bbeddaedd62a4c6b7d7494a93f845fc0fc3ce005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Wed, 10 Jul 2024 10:42:53 +0200 Subject: [PATCH 5/6] Run clang-format, add changelog entry. --- documentation/Changelog.md | 2 ++ include/codi/tapes/jacobianReuseTape.hpp | 21 +++++++++---------- .../tools/helpers/preaccumulationHelper.hpp | 12 ++++++----- include/codi/traits/numericLimits.hpp | 2 +- include/codi/traits/tapeTraits.hpp | 3 +-- ...ccumulationLocalAdjointsPreprocessTape.hpp | 3 ++- ...ntsPreprocessTapeForwardInvalidAdjoint.hpp | 3 ++- 7 files changed, 25 insertions(+), 21 deletions(-) diff --git a/documentation/Changelog.md b/documentation/Changelog.md index a1d7b665..fb875945 100644 --- a/documentation/Changelog.md +++ b/documentation/Changelog.md @@ -5,6 +5,8 @@ Changelog {#Changelog} - Features: * Tape evaluations with generalized custom adjoints. * Preaccumulation with local mapped adjoints. + * Edit identifiers in recorded tapes. + * Preaccumulation with a local adjoint vector after tape editing. ### v 2.2.0 - 2024-01-30 - Features: diff --git a/include/codi/tapes/jacobianReuseTape.hpp b/include/codi/tapes/jacobianReuseTape.hpp index 02ab285f..a40d60f2 100644 --- a/include/codi/tapes/jacobianReuseTape.hpp +++ b/include/codi/tapes/jacobianReuseTape.hpp @@ -271,18 +271,17 @@ namespace codi { /// \copydoc codi::EditingTapeInterface::editIdentifiers template void editIdentifiers(Func&& modifyIdentifier, Position const& start, Position const& end) { - auto evalFunc = [&modifyIdentifier]( - /* data from low level function byte data vector */ - size_t&, size_t const&, char*, - /* data from low level function info data vector */ - size_t&, size_t const&, Config::LowLevelFunctionToken* const, - Config::LowLevelFunctionDataSize* const, - /* data from jacobianData */ - size_t& curJacobianPos, size_t const&, Real const* const, Identifier* const rhsIdentifiers, - /* data from statementData */ - size_t& curStmtPos, size_t const& endStmtPos, Identifier* const lhsIdentifiers, - Config::ArgumentSize const* const numberOfJacobians) { + /* data from low level function byte data vector */ + size_t&, size_t const&, char*, + /* data from low level function info data vector */ + size_t&, size_t const&, Config::LowLevelFunctionToken* const, + Config::LowLevelFunctionDataSize* const, + /* data from jacobianData */ + size_t& curJacobianPos, size_t const&, Real const* const, Identifier* const rhsIdentifiers, + /* data from statementData */ + size_t& curStmtPos, size_t const& endStmtPos, Identifier* const lhsIdentifiers, + Config::ArgumentSize const* const numberOfJacobians) { while (curStmtPos < endStmtPos) CODI_Likely { Config::ArgumentSize const argsSize = numberOfJacobians[curStmtPos]; diff --git a/include/codi/tools/helpers/preaccumulationHelper.hpp b/include/codi/tools/helpers/preaccumulationHelper.hpp index 1bf9fbcd..16c2ebd6 100644 --- a/include/codi/tools/helpers/preaccumulationHelper.hpp +++ b/include/codi/tools/helpers/preaccumulationHelper.hpp @@ -202,7 +202,8 @@ namespace codi { addOutputRecursive(outputs...); tape.setPassive(); - computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise computeJacobianLocalMappedAdjoints + computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise + // computeJacobianLocalMappedAdjoints storeJacobian(); tape.setActive(); } @@ -222,7 +223,8 @@ namespace codi { tape.setPassive(); if (std::min(inputData.size(), outputData.size()) > 1) { - computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise computeJacobianLocalMappedAdjoints + computeJacobianLocalAdjointsPreprocessTapeIfAvailable(); // otherwise + // computeJacobianLocalMappedAdjoints } else { computeJacobianLocalMappedAdjoints(); } @@ -406,9 +408,9 @@ namespace codi { std::vector localAdjoints(nextIdentifier); // Preaccumulation with remapped identifiers on local adjoints. - Algorithms::computeJacobianCustomAdjoints(startPos, endPos, newInputData.data(), newInputData.size(), - newOutputData.data(), newOutputData.size(), jacobian, - localAdjoints.data()); + Algorithms::computeJacobianCustomAdjoints(startPos, endPos, newInputData.data(), + newInputData.size(), newOutputData.data(), + newOutputData.size(), jacobian, localAdjoints.data()); tape.resetTo(startPos, false); } diff --git a/include/codi/traits/numericLimits.hpp b/include/codi/traits/numericLimits.hpp index dbc1ca41..7f924e52 100644 --- a/include/codi/traits/numericLimits.hpp +++ b/include/codi/traits/numericLimits.hpp @@ -69,7 +69,7 @@ namespace std { } ///< See numeric_limits static Type constexpr lowest() { return Type(numeric_limits::lowest()); - } ///< See numeric_limits + } ///< See numeric_limits static int constexpr digits = numeric_limits::digits; ///< See numeric_limits static int constexpr digits10 = numeric_limits::digits10; ///< See numeric_limits static bool constexpr is_signed = numeric_limits::is_signed; ///< See numeric_limits diff --git a/include/codi/traits/tapeTraits.hpp b/include/codi/traits/tapeTraits.hpp index b8f4047f..b99dc54a 100644 --- a/include/codi/traits/tapeTraits.hpp +++ b/include/codi/traits/tapeTraits.hpp @@ -161,8 +161,7 @@ namespace codi { #ifndef DOXYGEN_DISABLE template - struct SupportsEditing, Tape>::type> + struct SupportsEditing, Tape>::type> : std::true_type {}; #endif diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp index be25da48..18a9b395 100644 --- a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTape.hpp @@ -34,7 +34,8 @@ */ #include "basePreaccumulation.hpp" -struct TestPreaccumulationLocalAdjointsPreprocessTape : public BasePreaccumulation { +struct TestPreaccumulationLocalAdjointsPreprocessTape + : public BasePreaccumulation { public: NAME("PreaccumulationLocalAdjointsPreprocessTape") diff --git a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp index 003c4139..5a45c000 100644 --- a/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp +++ b/tests/general/include/tests/tools/helpers/testPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint.hpp @@ -35,7 +35,8 @@ #include "basePreaccumulationForwardInvalidAdjoint.hpp" struct TestPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint - : public BasePreaccumulationForwardInvalidAdjoint { + : public BasePreaccumulationForwardInvalidAdjoint< + TestPreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint> { public: NAME("PreaccumulationLocalAdjointsPreprocessTapeForwardInvalidAdjoint") From 9a381aca5b3fecc95320ed87553c956e9a50c5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Bl=C3=BChdorn?= Date: Fri, 19 Jul 2024 15:48:09 +0200 Subject: [PATCH 6/6] Update comment. --- include/codi/tools/helpers/preaccumulationHelper.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/codi/tools/helpers/preaccumulationHelper.hpp b/include/codi/tools/helpers/preaccumulationHelper.hpp index 16c2ebd6..62b31c58 100644 --- a/include/codi/tools/helpers/preaccumulationHelper.hpp +++ b/include/codi/tools/helpers/preaccumulationHelper.hpp @@ -212,8 +212,8 @@ namespace codi { } /// Finish the preaccumulation region and perform the preaccumulation. Uses local adjoints instead of adjoints - /// from the tape. Forwards to finishLocalMappedAdjoints or finishLocalAdjointsPreprocessTape, depending on which - /// is more efficient given the numbers of inputs and outputs. See `addOutput()` for outputs. + /// from the tape. Behaves either like finishLocalMappedAdjoints or like finishLocalAdjointsPreprocessTape, + /// depending on which is more efficient given the numbers of inputs and outputs. See `addOutput()` for outputs. template void finishLocalAdjoints(Outputs&... outputs) { Tape& tape = Type::getTape();