Skip to content

Commit

Permalink
Merge release-next into ornl-next
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-builder committed May 10, 2024
2 parents 929cf9e + 93af013 commit e34140c
Show file tree
Hide file tree
Showing 1,476 changed files with 48,256 additions and 39,896 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automerge.yml
Expand Up @@ -42,7 +42,7 @@ jobs:
steps:
- uses: actions/checkout@master

- name: Merge ornl-next into main
- name: Merge release-next into ornl-next
uses: devmasx/merge-branch@master
with:
type: now
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Expand Up @@ -55,14 +55,14 @@ repos:
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.1
rev: v0.4.3
# ruff must appear before black in the list of hooks
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black
rev: 24.4.0
rev: 24.4.2
hooks:
- id: black
exclude: scripts/templates/reference/|Testing/Tools/cxxtest
6 changes: 3 additions & 3 deletions CITATION.cff
Expand Up @@ -6,9 +6,9 @@ authors:
email: mantid-help@mantidproject.org
website: https://www.mantidproject.org/
title: Manipulation and Analysis Toolkit for Instrument Data
version: 6.8.0
doi: 10.5286/Software/Mantid6.8
date-released: 2023-10-12
version: 6.9.1
doi: 10.5286/Software/Mantid6.9.1
date-released: 2024-03-26
keywords:
- mantid
- neutron
Expand Down
32 changes: 15 additions & 17 deletions Framework/API/src/AlgorithmManager.cpp
Expand Up @@ -111,17 +111,16 @@ IAlgorithm_sptr AlgorithmManagerImpl::getAlgorithm(AlgorithmID id) const {
*/
void AlgorithmManagerImpl::removeById(AlgorithmID id) {
std::lock_guard<std::recursive_mutex> _lock(this->m_managedMutex);
auto itend = m_managed_algs.end();
for (auto it = m_managed_algs.begin(); it != itend; ++it) {
if ((**it).getAlgorithmID() == id) {
if (!(*it)->isRunning()) {
g_log.debug() << "Removing algorithm " << (*it)->name() << '\n';
m_managed_algs.erase(it);
} else {
g_log.debug() << "Unable to remove algorithm " << (*it)->name() << ". The algorithm is running.\n";
}
break;
}
const auto it = std::find_if(m_managed_algs.cbegin(), m_managed_algs.cend(),
[&id](const auto &alg) { return alg->getAlgorithmID() == id; });
if (it == m_managed_algs.cend()) {
return;
}
if (!(*it)->isRunning()) {
g_log.debug() << "Removing algorithm " << (*it)->name() << '\n';
m_managed_algs.erase(it);
} else {
g_log.debug() << "Unable to remove algorithm " << (*it)->name() << ". The algorithm is running.\n";
}
}

Expand Down Expand Up @@ -174,12 +173,11 @@ size_t AlgorithmManagerImpl::removeFinishedAlgorithms() {
std::copy_if(m_managed_algs.cbegin(), m_managed_algs.cend(), std::back_inserter(theCompletedInstances),
[](const auto &algorithm) { return (algorithm->isReadyForGarbageCollection()); });
for (auto completedAlg : theCompletedInstances) {
auto itend = m_managed_algs.end();
for (auto it = m_managed_algs.begin(); it != itend; ++it) {
if ((**it).getAlgorithmID() == completedAlg->getAlgorithmID()) {
m_managed_algs.erase(it);
break;
}
const auto it = std::find_if(m_managed_algs.begin(), m_managed_algs.end(), [&completedAlg](const auto &alg) {
return alg->getAlgorithmID() == completedAlg->getAlgorithmID();
});
if (it != m_managed_algs.end()) {
m_managed_algs.erase(it);
}
}
return theCompletedInstances.size();
Expand Down
2 changes: 1 addition & 1 deletion Framework/API/src/CompositeFunction.cpp
Expand Up @@ -965,7 +965,7 @@ size_t CompositeFunction::getNumberDomains() const {
}
size_t nd = getFunction(0)->getNumberDomains();
for (size_t iFun = 1; iFun < n; ++iFun) {
if (getFunction(0)->getNumberDomains() != nd) {
if (getFunction(iFun)->getNumberDomains() != nd) {
throw std::runtime_error("CompositeFunction has members with "
"inconsistent domain numbers.");
}
Expand Down
11 changes: 3 additions & 8 deletions Framework/API/src/FileProperty.cpp
Expand Up @@ -287,16 +287,11 @@ bool FileProperty::extsMatchRunFiles() {
try {
Kernel::FacilityInfo facilityInfo = Kernel::ConfigService::Instance().getFacility();
const std::vector<std::string> facilityExts = facilityInfo.extensions();
auto facilityExtsBegin = facilityExts.cbegin();
auto facilityExtsEnd = facilityExts.cend();
const std::vector<std::string> allowedExts = this->allowedValues();
match = std::any_of(allowedExts.cbegin(), allowedExts.cend(), [&facilityExts](const auto &ext) {
return std::find(facilityExts.cbegin(), facilityExts.cend(), ext) != facilityExts.cend();
});

for (const auto &ext : allowedExts) {
if (std::find(facilityExtsBegin, facilityExtsEnd, ext) != facilityExtsEnd) {
match = true;
break;
}
}
} catch (Mantid::Kernel::Exception::NotFoundError &) {
} // facility could not be found, do nothing this will return the default
// match of false
Expand Down
16 changes: 8 additions & 8 deletions Framework/API/src/IFunction.cpp
Expand Up @@ -417,11 +417,10 @@ IConstraint *IFunction::getConstraint(size_t i) const {
*/
void IFunction::removeConstraint(const std::string &parName) {
size_t iPar = parameterIndex(parName);
for (auto it = m_constraints.begin(); it != m_constraints.end(); ++it) {
if (iPar == (**it).getLocalIndex()) {
m_constraints.erase(it);
break;
}
const auto it = std::find_if(m_constraints.cbegin(), m_constraints.cend(),
[&iPar](const auto &constraint) { return iPar == constraint->getLocalIndex(); });
if (it != m_constraints.cend()) {
m_constraints.erase(it);
}
}

Expand Down Expand Up @@ -456,7 +455,7 @@ void IFunction::setUpForFit() {
std::string IFunction::writeConstraints() const {
std::ostringstream stream;
bool first = true;
for (auto &constrint : m_constraints) {
for (const auto &constrint : m_constraints) {
if (constrint->isDefault())
continue;
if (!first) {
Expand Down Expand Up @@ -730,7 +729,7 @@ std::string IFunction::Attribute::asUnquotedString() const {
if (*(attr.begin()) == '\"')
unquoted = std::string(attr.begin() + 1, attr.end() - 1);
if (*(unquoted.end() - 1) == '\"')
unquoted = std::string(unquoted.begin(), unquoted.end() - 1);
unquoted.resize(unquoted.size() - 1);

return unquoted;
}
Expand Down Expand Up @@ -1674,7 +1673,8 @@ IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(const std::s
template <>
MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(const std::string &name) const {
auto *prop = dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>> *>(getPointerToProperty(name));
const auto *prop =
dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>> *>(getPointerToProperty(name));
if (prop) {
return prop->operator()();
} else {
Expand Down
40 changes: 39 additions & 1 deletion Framework/API/test/CompositeFunctionTest.h
Expand Up @@ -139,6 +139,31 @@ template <bool withAttributes = false> class Gauss : public IPeakFunction {
void setFwhm(const double w) override { setParameter(2, w); }
};

// Create class with configurable number of domains for ease of testing.
class FunctionWithNDomains : public IPeakFunction {
public:
FunctionWithNDomains(int nDomains) : m_nDomains(nDomains) {}

size_t getNumberDomains() const override { return m_nDomains; }

// Override pure virtual functions.
std::string name() const override { return "FunctionWithNDomains"; }
double fwhm() const override { return 1; }
void setFwhm(const double w) override { UNUSED_ARG(w); }
void functionLocal(double *out, const double *xValues, const size_t nData) const override {
UNUSED_ARG(out);
UNUSED_ARG(xValues);
UNUSED_ARG(nData);
}
double centre() const override { return 1; }
double height() const override { return 1; }
void setCentre(const double c) override { UNUSED_ARG(c); }
void setHeight(const double h) override { UNUSED_ARG(h); }

private:
size_t m_nDomains;
};

template <bool withAttributes = false> class Linear : public ParamFunction, public IFunction1D {
public:
Linear() {
Expand Down Expand Up @@ -1334,7 +1359,7 @@ class CompositeFunctionTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(mfun->getAttribute("NumDeriv").asBool(), true);
}

void test_set_attribute_thorws_if_attribute_not_recongized() {
void test_set_attribute_throws_if_attribute_not_recongized() {
auto mfun = std::make_unique<CompositeFunction>();
auto gauss = std::make_shared<Gauss<true>>();
auto background = std::make_shared<Linear<true>>();
Expand Down Expand Up @@ -1517,6 +1542,19 @@ class CompositeFunctionTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(composite->getFunction(1)->calculateStepSize(parameterValue2), parameterValue2 * sqrtEpsilon);
}

void test_getNumberDomains_throws_with_inconsistent_domain_numbers() {
IFunction_sptr f1 = IFunction_sptr(new FunctionWithNDomains(7));
IFunction_sptr f2 = IFunction_sptr(new FunctionWithNDomains(13));

CompositeFunction fun;

fun.addFunction(f1);
fun.addFunction(f2);

TS_ASSERT_THROWS_EQUALS(fun.getNumberDomains(), const std::runtime_error &e, std::string(e.what()),
"CompositeFunction has members with inconsistent domain numbers.");
}

private:
CompositeFunction_sptr createComposite() {
auto composite = std::make_unique<CompositeFunction>();
Expand Down
15 changes: 15 additions & 0 deletions Framework/Algorithms/CMakeLists.txt
Expand Up @@ -237,9 +237,14 @@ set(SRC_FILES
src/Plus.cpp
src/PointByPointVCorrection.cpp
src/PoissonErrors.cpp
src/PolarizationCorrections/HeliumAnalyserEfficiency.cpp
src/PolarizationCorrections/PolarizationCorrectionsHelpers.cpp
src/PolarizationCorrections/SpinStateValidator.cpp
src/PolarizationCorrectionFredrikze.cpp
src/PolarizationCorrectionWildes.cpp
src/PolarizationEfficiencyCor.cpp
src/PolarizationCorrections/DepolarizedAnalyserTransmission.cpp
src/PolarizationCorrections/FlipperEfficiency.cpp
src/PolynomialCorrection.cpp
src/Power.cpp
src/PowerLawCorrection.cpp
Expand Down Expand Up @@ -588,6 +593,11 @@ set(INC_FILES
inc/MantidAlgorithms/Plus.h
inc/MantidAlgorithms/PointByPointVCorrection.h
inc/MantidAlgorithms/PoissonErrors.h
inc/MantidAlgorithms/PolarizationCorrections/DepolarizedAnalyserTransmission.h
inc/MantidAlgorithms/PolarizationCorrections/HeliumAnalyserEfficiency.h
inc/MantidAlgorithms/PolarizationCorrections/PolarizationCorrectionsHelpers.h
inc/MantidAlgorithms/PolarizationCorrections/SpinStateValidator.h
inc/MantidAlgorithms/PolarizationCorrections/FlipperEfficiency.h
inc/MantidAlgorithms/PolarizationCorrectionFredrikze.h
inc/MantidAlgorithms/PolarizationCorrectionWildes.h
inc/MantidAlgorithms/PolarizationEfficiencyCor.h
Expand Down Expand Up @@ -934,6 +944,11 @@ set(TEST_FILES
PlusTest.h
PointByPointVCorrectionTest.h
PoissonErrorsTest.h
PolarizationCorrections/DepolarizedAnalyserTransmissionTest.h
PolarizationCorrections/HeliumAnalyserEfficiencyTest.h
PolarizationCorrections/PolarizationCorrectionsHelpersTest.h
PolarizationCorrections/SpinStateValidatorTest.h
PolarizationCorrections/FlipperEfficiencyTest.h
PolarizationCorrectionFredrikzeTest.h
PolarizationCorrectionWildesTest.h
PolarizationEfficiencyCorTest.h
Expand Down
2 changes: 1 addition & 1 deletion Framework/Algorithms/inc/MantidAlgorithms/FitPeaks.h
Expand Up @@ -214,7 +214,7 @@ class MANTID_ALGORITHMS_DLL FitPeaks final : public API::Algorithm {
const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);

/// calculate peak+background for fitted
void calculateFittedPeaks(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_results);
void calculateFittedPeaks(const std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> &fit_results);

/// Get the parameter name for peak height (I or height or etc)
std::string getPeakHeightParameterName(const API::IPeakFunction_const_sptr &peak_function);
Expand Down
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup_fwd.h"
#include "MantidAlgorithms/DllConfig.h"

Expand Down
@@ -0,0 +1,49 @@
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2024 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAlgorithms/DllConfig.h"

namespace Mantid::Algorithms {

class MANTID_ALGORITHMS_DLL DepolarizedAnalyserTransmission : public API::Algorithm {
public:
/// The string identifier for the algorithm. @see Algorithm::name
std::string const name() const override { return "DepolarizedAnalyserTransmission"; }

/// A summary of the algorithm's purpose. @see Algorithm::summary
std::string const summary() const override;

/// The category of the algorithm. @see Algorithm::category
std::string const category() const override { return "SANS\\PolarizationCorrections"; }

/// The version number of the algorithm. @see Algorithm::version
int version() const override { return 1; }

private:
/// Setup the algorithm's properties and prepare constants.
void init() override;

/// Execute the algorithm with the provided properties.
void exec() override;

/// Validate the provided properties to the algorithm.
std::map<std::string, std::string> validateInputs() override;

/// Divide the depolarized workspace by the empty cell workspace.
API::MatrixWorkspace_sptr calcDepolarizedProportion();

/// Fit using UserFunction1D to find the pxd and transmission values.
void calcWavelengthDependentTransmission(API::MatrixWorkspace_sptr const &inputWs, std::string const &outputWsName);

/// Calculate and output the non-normalised covariance matrix for the fit.
void calcNonNormCovarianceMatrix(API::ITableWorkspace_sptr const &normCovMatrix,
API::ITableWorkspace_sptr const &paramsWs);
};
} // namespace Mantid::Algorithms
@@ -0,0 +1,45 @@
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2024 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAlgorithms/DllConfig.h"

namespace Mantid::Algorithms {

class MANTID_ALGORITHMS_DLL FlipperEfficiency : public API::Algorithm {
public:
/// The string identifier for the algorithm. @see Algorithm::name
std::string const name() const override { return "FlipperEfficiency"; }

/// A summary of the algorithm's purpose. @see Algorithm::summary
std::string const summary() const override;

/// The category of the algorithm. @see Algorithm::category
std::string const category() const override { return "SANS\\PolarizationCorrections"; }

/// The version number of the algorithm. @see Algorithm::version
int version() const override { return 1; }

private:
/// Setup the algorithm's properties and prepare constants.
void init() override;

/// Execute the algorithm with the provided properties.
void exec() override;

/// Check that the inputs to the algorithm are valid.
std::map<std::string, std::string> validateInputs() override;

/// Save the given workspace to a given path as Nexus, applying the relevant extension if necessary.
void saveToFile(API::MatrixWorkspace_sptr const &workspace, std::string const &filePathStr);

/// Perform the main calculation for determining the efficiency on the given group.
API::MatrixWorkspace_sptr calculateEfficiency(API::WorkspaceGroup_sptr const &groupWs);
};
} // namespace Mantid::Algorithms

0 comments on commit e34140c

Please sign in to comment.