Skip to content

Commit

Permalink
Fix tests and CI workflows to load spack environment before starting …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
koparasy committed Jun 4, 2024
1 parent c8fb053 commit 7bccc05
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 164 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ jobs:
- name: Run tests Torch=On FAISS=On HDF5=On AMS
run: |
cd build
make test
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
env CTEST_OUTPUT_ON_FAILURE=1 make test
- name: Build CALIPER=Off Torch=Off FAISS=On HDF5=On AMS
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -131,7 +133,9 @@ jobs:
- name: Run tests Torch=Off FAISS=On HDF5=On AMS
run: |
cd build
make test
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
env CTEST_OUTPUT_ON_FAILURE=1 make test
- name: Build Torch=Off FAISS=Off HDF5=On AMS
shell: bash -l {0}
run: |
Expand Down Expand Up @@ -168,6 +172,8 @@ jobs:
- name: Run tests Torch=Off FAISS=Off HDF5=On AMS
run: |
cd build
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
make test
- name: Build Torch=Off FAISS=Off HDF5=Off AMS
shell: bash -l {0}
Expand Down Expand Up @@ -202,6 +208,8 @@ jobs:
- name: Run tests Torch=Off FAISS=Off HDF5=Off AMS
run: |
cd build
source /spack/share/spack/setup-env.sh
spack env activate -p /ams-spack-env
make test
build-cuda-tests:
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ find_package(UMPIRE REQUIRED
list(APPEND AMS_APP_LIBRARIES umpire)
list(APPEND AMS_APP_INCLUDES ${UMPIRE_INCLUDE_DIR})

find_package(nlohmann_json REQUIRED)
list(APPEND AMS_APP_LIBRARIES nlohmann_json::nlohmann_json)

# ------------------------------------------------------------------------------
find_package(Threads REQUIRED)

Expand Down
2 changes: 2 additions & 0 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ int run(const char *device_name,
dbType = AMSDBType::AMS_RMQ;
}

if (db_config == nullptr) dbType = AMSDBType::AMS_NONE;


if (dbType != AMSDBType::AMS_RMQ) {
AMSConfigureFSDatabase(dbType, db_config);
Expand Down
115 changes: 58 additions & 57 deletions src/AMSlib/AMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ struct AMSAbstractModel {
{

/*
* Empth models can exist in cases were the user annotates
* Empty models can exist in cases were the user annotates
* the code without having data to train a model. In such a case,
* the user deploys withou specifying the model and lib AMS will
* the user deploys without specifying the model and lib AMS will
* collect everything
*/
if (!jRoot.contains("model_path")) {
Expand Down Expand Up @@ -198,7 +198,7 @@ struct AMSAbstractModel {
if (uq_path != nullptr) UQPath = std::string(uq_path);

this->threshold = threshold;
num_clusters = num_clusters;
nClusters = num_clusters;
DBG(AMS,
"Registered Model %s %g",
BaseUQ::UQPolicyToStr(uqPolicy).c_str(),
Expand Down Expand Up @@ -269,59 +269,57 @@ class AMSWrap
json &jRoot,
std::unordered_map<std::string, std::string> ml_domain_mapping)
{
if (jRoot.contains("ml_models")) {
auto models = jRoot["ml_models"];
for (auto &field : models.items()) {
// We skip models not registered to respective domains. We will not use
// those.
auto &key = field.key();
if (ml_domain_mapping.find(key) == ml_domain_mapping.end()) continue;

if (ams_candidate_models.find(ml_domain_mapping[key]) !=
ams_candidate_models.end()) {
FATAL(AMS,
"Domain Model %s has multiple ml model mappings",
ml_domain_mapping[key].c_str())
}

registered_models.push_back(AMSAbstractModel(field.value()));
// We add the value of the domain mappings, as the application can
// only query based on these.
ams_candidate_models.emplace(ml_domain_mapping[key],
registered_models.size() - 1);
if (!jRoot.contains("ml_models")) return;
auto models = jRoot["ml_models"];
for (auto &field : models.items()) {
// We skip models not registered to respective domains. We will not use
// those.
auto &key = field.key();
if (ml_domain_mapping.find(key) == ml_domain_mapping.end()) continue;

if (ams_candidate_models.find(ml_domain_mapping[key]) !=
ams_candidate_models.end()) {
FATAL(AMS,
"Domain Model %s has multiple ml model mappings",
ml_domain_mapping[key].c_str())
}

registered_models.push_back(AMSAbstractModel(field.value()));
// We add the value of the domain mappings, as the application can
// only query based on these.
ams_candidate_models.emplace(ml_domain_mapping[key],
registered_models.size() - 1);
}
}

void parseDatabase(json &jRoot)
{
DBG(AMS, "Parsing Data Base Fields")
if (jRoot.contains("db")) {
auto entry = jRoot["db"];
if (!entry.contains("dbType"))
if (!jRoot.contains("db")) return;
auto entry = jRoot["db"];
if (!entry.contains("dbType"))
THROW(std::runtime_error,
"JSON file instantiates db-fields without defining a "
"\"dbType\" "
"entry");
auto dbStrType = entry["dbType"].get<std::string>();
DBG(AMS, "DB Type is: %s", dbStrType.c_str())
AMSDBType dbType = ams::db::getDBType(dbStrType);
if (dbType == AMSDBType::AMS_NONE) return;

if (dbType == AMSDBType::AMS_CSV || dbType == AMSDBType::AMS_HDF5) {
if (!entry.contains("fs_path"))
THROW(std::runtime_error,
"JSON file instantiates db-fields without defining a "
"\"dbType\" "
"entry");
auto dbStrType = entry["dbType"].get<std::string>();
DBG(AMS, "DB Type is: %s", dbStrType.c_str())
AMSDBType dbType = ams::db::getDBType(dbStrType);
if (dbType == AMSDBType::AMS_NONE) return;

if (dbType == AMSDBType::AMS_CSV || dbType == AMSDBType::AMS_HDF5) {
if (!entry.contains("fs_path"))
THROW(std::runtime_error,
"JSON db-fiels does not provide file system path");

std::string db_path = entry["fs_path"].get<std::string>();
auto &DB = ams::db::DBManager::getInstance();
DB.instantiate_fs_db(dbType, db_path);
DBG(AMS,
"Configured AMS File system database to point to %s using file "
"type %s",
db_path.c_str(),
dbStrType.c_str());
}
"JSON db-fiels does not provide file system path");

std::string db_path = entry["fs_path"].get<std::string>();
auto &DB = ams::db::DBManager::getInstance();
DB.instantiate_fs_db(dbType, db_path);
DBG(AMS,
"Configured AMS File system database to point to %s using file "
"type %s",
db_path.c_str(),
dbStrType.c_str());
}
}

Expand Down Expand Up @@ -410,7 +408,7 @@ void _AMSExecute(AMSExecutor executor,
int inputDim,
int outputDim)
{
long index = static_cast<long>(executor);
int64_t index = static_cast<int64_t>(executor);
if (index >= _amsWrap.executors.size())
throw std::runtime_error("AMS Executor identifier does not exist\n");
auto currExec = _amsWrap.executors[index];
Expand Down Expand Up @@ -551,7 +549,7 @@ void AMSExecute(AMSExecutor executor,

void AMSDestroyExecutor(AMSExecutor executor)
{
long index = static_cast<long>(executor);
int64_t index = static_cast<int64_t>(executor);
if (index >= _amsWrap.executors.size())
throw std::runtime_error("AMS Executor identifier does not exist\n");
auto currExec = _amsWrap.executors[index];
Expand Down Expand Up @@ -587,13 +585,16 @@ AMSCAbstrModel AMSRegisterAbstractModel(const char *domain_name,
const char *db_label,
int num_clusters)
{
int id = _amsWrap.register_model(domain_name,
uq_policy,
threshold,
surrogate_path,
uq_path,
db_label,
num_clusters);
auto id = _amsWrap.get_model_index(domain_name);
if (id == -1) {
id = _amsWrap.register_model(domain_name,
uq_policy,
threshold,
surrogate_path,
uq_path,
db_label,
num_clusters);
}

return id;
}
Expand Down
6 changes: 3 additions & 3 deletions src/AMSlib/include/AMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern "C" {

typedef void (*AMSPhysicFn)(void *, long, const void *const *, void *const *);

typedef long AMSExecutor;
typedef int64_t AMSExecutor;
typedef int AMSCAbstrModel;

typedef enum { AMS_SINGLE = 0, AMS_DOUBLE } AMSDType;
Expand All @@ -60,15 +60,15 @@ typedef enum { AMS_UBALANCED = 0, AMS_BALANCED } AMSExecPolicy;

typedef enum { AMS_NONE = 0, AMS_CSV, AMS_REDIS, AMS_HDF5, AMS_RMQ } AMSDBType;

typedef enum {
enum struct AMSUQPolicy {
AMS_UQ_BEGIN = 0,
AMS_FAISS_MEAN,
AMS_FAISS_MAX,
AMS_DELTAUQ_MEAN,
AMS_DELTAUQ_MAX,
AMS_RANDOM,
AMS_UQ_END
} AMSUQPolicy;
};


AMSExecutor AMSCreateExecutor(AMSCAbstrModel model,
Expand Down
2 changes: 1 addition & 1 deletion src/AMSlib/ml/hdcache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class HDCache
}
} else {
CFATAL(UQModule,
m_policy == AMSUQPolicy::FAISS_Max,
m_policy == AMSUQPolicy::AMS_FAISS_MAX,
"FAISS Max on device is not supported yet");

ams::Device::computePredicate(
Expand Down
1 change: 0 additions & 1 deletion src/AMSlib/ml/surrogate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef __AMS_SURROGATE_HPP__
#define __AMS_SURROGATE_HPP__

#include <cmath>
#include <experimental/filesystem>
#include <memory>
#include <stdexcept>
Expand Down
3 changes: 0 additions & 3 deletions src/AMSlib/ml/uq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "ml/surrogate.hpp"
#include "wf/resource_manager.hpp"

static inline bool isNullOrEmpty(const char *p) { return (!p || p[0] == '\0'); }

class BaseUQ
{
public:
Expand Down Expand Up @@ -204,7 +202,6 @@ class UQ : public BaseUQ

bool hasSurrogate() { return (surrogate ? true : false); }


private:
AMSUQPolicy uqPolicy;
FPTypeValue threshold;
Expand Down
Loading

0 comments on commit 7bccc05

Please sign in to comment.