Skip to content

setScriptLibrary/setScriptLibraryFromFile not working in SWIG/Python API #307

@rkapl123

Description

@rkapl123

Dear All!

Thank you for incorporating the mentioned functions into the python API, however it doesn't work for the reasons below:

First, the ScriptLibraryStorage singleton is set:

void InputParameters::setScriptLibrary(const std::string& xml) {
    ScriptLibraryData data;
    data.fromXMLString(xml);
    ScriptLibraryStorage::instance().set(std::move(data));
}

but this is cleaned, when starting OREApp run:

void OREApp::run(const std::vector<std::string>& marketData, const std::vector<std::string>& fixingData) {
    QL_REQUIRE(inputs_, "No InputParameters set");
    // Create a market data loader that takes input from the provided vectors
    auto loader = QuantLib::ext::make_shared<MarketDataInMemoryLoader>(inputs_, marketData, fixingData);
    run(loader);
}

void OREApp::run(const QuantLib::ext::shared_ptr<MarketDataLoader> loader) {

    // Only one thread at a time should call run
    static std::mutex _s_mutex;
    std::lock_guard<std::mutex> lock(_s_mutex);

    // Clean start, but leave Singletons intact after run is completed
    {
        CleanUpThreadLocalSingletons cleanupThreadLocalSingletons;
        CleanUpThreadGlobalSingletons cleanupThreadGloablSingletons;
        CleanUpLogSingleton cleanupLogSingleton(clearLog_, true);
    }

    // Use inputs when available, otherwise try params
    if (inputs_ != nullptr)
        initFromInputs();
    else if (params_ != nullptr)
        initFromParams();
    else {
        ALOG("both inputs are empty");
        return;
    }

for the InstrumentConventions singleton (and currency/calendar config) the loss of information in CleanUpThreadGlobalSingletons is taken care of by setting them again:

void OREApp::initFromInputs() {
    // Initialise Singletons
    Settings::instance().evaluationDate() = inputs_->asof();
    InstrumentConventions::instance().setConventions(inputs_->conventions());

    if (inputs_->currencyConfigs() != nullptr)
        inputs_->currencyConfigs()->addCurrencies();
    if (inputs_->calendarAdjustmentConfigs() != nullptr)
        inputs_->calendarAdjustmentConfigs()->addCalendars();

    if (console_) {
        ConsoleLog::instance().switchOn();
    }

    outputPath_ = inputs_->resultsPath().string();
    if (clearLog_)
        setupLog(logMask_, outputPath_, logFile_, logRootPath_, progressLogFile_, progressLogRotationSize_,
                 progressLogToConsole_, structuredLogFile_, structuredLogRotationSize_);
    LOG("initFromInputs done, requested analytics:" << to_string(inputs_->analytics()));
}

but this is missing for the ScriptLibraryStorage...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions