Skip to content

Commit

Permalink
Print model metadata & citations
Browse files Browse the repository at this point in the history
  • Loading branch information
Luthaf committed Apr 17, 2024
1 parent 893fe99 commit 01d6349
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 4 additions & 2 deletions regtest/metatensor/rt-soap/soap_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ def forward(
soap_block = soap.block()
projected = soap_block.values @ self.pca_projection

samples = soap_block.samples.remove("center_type")

block = TensorBlock(
values=projected,
samples=soap_block.samples,
samples=samples,
components=[],
properties=Labels("soap_pca", torch.tensor([[0], [1], [2]], device=device)),
)
Expand Down Expand Up @@ -99,7 +101,7 @@ def forward(
description="""
A simple collective variable for testing purposes
""",
authors=["..."],
authors=["Some Author"],
references={
"implementation": ["ref to SOAP code"],
"architecture": ["ref to SOAP"],
Expand Down
13 changes: 11 additions & 2 deletions src/metatensor/metatensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,26 @@ MetatensorPlumedAction::MetatensorPlumedAction(const ActionOptions& options):
try {
this->model_ = metatensor_torch::load_atomistic_model(model_path, extensions_directory);
} catch (const std::exception& e) {
error("failed to load model at '" + model_path + "': " + e.what());
this->error("failed to load model at '" + model_path + "': " + e.what());
}

// extract information from the model
auto metadata = this->model_.run_method("metadata").toCustomClass<metatensor_torch::ModelMetadataHolder>();
this->capabilities_ = this->model_.run_method("capabilities").toCustomClass<metatensor_torch::ModelCapabilitiesHolder>();
auto requests_ivalue = this->model_.run_method("requested_neighbors_lists");
for (auto request_ivalue: requests_ivalue.toList()) {
auto request = request_ivalue.get().toCustomClass<metatensor_torch::NeighborsListOptionsHolder>();
this->nl_requests_.push_back(request);
}

log.printf("\n%s\n", metadata->print().c_str());
// add the model references to PLUMED citation handling mechanism
for (const auto& it: metadata->references) {
for (const auto& ref: it.value()) {
this->cite(ref);
}
}

// parse the atomic types from the input file
std::vector<int32_t> atomic_types;
std::vector<int32_t> species_to_types;
Expand All @@ -168,7 +177,7 @@ MetatensorPlumedAction::MetatensorPlumedAction(const ActionOptions& options):
int32_t type = i;
if (has_custom_types) {
if (species_to_types.size() < static_cast<size_t>(i)) {
error(
this->error(
"SPECIES_TO_TYPES is too small, it should have one entry "
"for each species (we have at least " + std::to_string(i) +
" species and " + std::to_string(species_to_types.size()) +
Expand Down

0 comments on commit 01d6349

Please sign in to comment.