Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/mnist-learn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_executable(${PROJECT_NAME}
parse_arguments.cpp
dataset.cpp
evaluate_results.cpp
network_validation.cpp
models/blifat/construct_network.cpp
models/blifat/prepare_network_for_inference.cpp
models/blifat/spike_generators.cpp
Expand Down
3 changes: 3 additions & 0 deletions examples/mnist-learn/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "dataset.h"
#include "evaluate_results.h"
#include "inference.h"
#include "network_validation.h"
#include "parse_arguments.h"
#include "save_network.h"
#include "training.h"
Expand All @@ -41,6 +42,8 @@ void run_model(const ModelDescription& model_desc)

AnnotatedNetwork network = construct_network<Neuron>(model_desc);

validate_network(network.network_);

// Online Help link: https://click.kaspersky.com/?hl=en-US&version=2.0&pid=KNP&link=online_help&helpid=243548
knp::framework::BackendLoader backend_loader;
train_model<Neuron>(model_desc, dataset, network, backend_loader);
Expand Down
33 changes: 33 additions & 0 deletions examples/mnist-learn/network_validation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @file network_validation.cpp
* @brief Function to validate network.
* @kaspersky_support D. Postnikov
* @date 03.04.2026
* @license Apache 2.0
* @copyright © 2026 AO Kaspersky Lab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "network_validation.h"

#include <knp/framework/network_validation/executor.h>
#include <knp/framework/network_validation/validators/connectivity.h>


void validate_network(const knp::framework::Network& network)
{
knp::framework::network_validation::Executor validations_executor;
validations_executor.add_validator("Connectivity validator", knp::framework::network_validation::Connectivity());
validations_executor.run_validators(network);
}
31 changes: 31 additions & 0 deletions examples/mnist-learn/network_validation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file network_validation.h
* @brief Function to validate network.
* @kaspersky_support D. Postnikov
* @date 03.04.2026
* @license Apache 2.0
* @copyright © 2026 AO Kaspersky Lab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <knp/framework/network.h>


/**
* @brief Run validation on specified network.
* @param network Network for validation.
*/
void validate_network(const knp::framework::Network& network);
2 changes: 2 additions & 0 deletions knp/base-framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ knp_add_library("${PROJECT_NAME}-core"
impl/output_channel.cpp
impl/synchronization.cpp
impl/monitoring/model.cpp
impl/network_validation/executor.cpp
impl/network_validation/validators/connectivity.cpp
impl/projection/wta.cpp
impl/sonata/save_network.cpp
impl/sonata/load_network.cpp
Expand Down
160 changes: 160 additions & 0 deletions knp/base-framework/impl/network_validation/executor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* @file executor.cpp
* @brief Network validators executor.
* @kaspersky_support David P.
* @date 08.04.2026
* @license Apache 2.0
* @copyright © 2026 AO Kaspersky Lab
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <knp/framework/network_validation/executor.h>
#include <knp/framework/tags/name.h>

#include <spdlog/spdlog.h>


namespace knp::framework::network_validation
{

knp::core::UID Executor::add_validator(std::string name, PopulationValidator validator)
{
knp::core::UID uid;
population_validators_[uid] = {std::move(name), std::move(validator)};
return uid;
}


knp::core::UID Executor::add_validator(PopulationValidator validator)
{
knp::core::UID uid;
population_validators_[uid] = {
"Populations validator #" + std::to_string(population_validators_.size()), std::move(validator)};
return uid;
}


knp::core::UID Executor::add_validator(std::string name, ProjectionValidator validator)
{
knp::core::UID uid;
projection_validators_[uid] = {std::move(name), std::move(validator)};
return uid;
}


knp::core::UID Executor::add_validator(ProjectionValidator validator)
{
knp::core::UID uid;
projection_validators_[uid] = {
"Projections validator #" + std::to_string(projection_validators_.size()), std::move(validator)};
return uid;
}


knp::core::UID Executor::add_validator(std::string name, NetworkValidator validator)
{
knp::core::UID uid;
network_validators_[uid] = {std::move(name), std::move(validator)};
return uid;
}


knp::core::UID Executor::add_validator(NetworkValidator validator)
{
knp::core::UID uid;
network_validators_[uid] = {
"Network validator #" + std::to_string(network_validators_.size()), std::move(validator)};
return uid;
}


void Executor::log_report(const Report& report)
{
for (const auto& issue : report)
{
switch (issue.severity_)
{
case IssueSeverity::info:
SPDLOG_INFO("[{}] {}", issue.code_.value(), issue.message_);
break;
case IssueSeverity::warning:
SPDLOG_WARN("[{}] {}", issue.code_.value(), issue.message_);
break;
case IssueSeverity::error:
SPDLOG_ERROR("[{}] {}", issue.code_.value(), issue.message_);
break;
default:
throw std::logic_error("Unknown severity level.");
}
}
}


std::vector<Executor::ValidatorResult> Executor::run_validators(const Network& network)
{
std::vector<ValidatorResult> reports;

if (population_validators_.size())
{
SPDLOG_INFO("Starting population validators.");
for (auto& validator : population_validators_)
{
for (const auto& pop : network.get_populations())
{
SPDLOG_INFO(
"Running \"{}\" on population \"{}\".", std::string(validator.second.first),
std::visit([](auto&& pop) { return knp::framework::tags::get_name(pop); }, pop));
auto report = validator.second.second(pop);
log_report(report);
reports.push_back({validator.first, validator.second.first, std::move(report)});
}
}
SPDLOG_INFO("Finished population validators.");
}

if (projection_validators_.size())
{
SPDLOG_INFO("Starting projection validators.");
for (auto& validator : projection_validators_)
{
for (const auto& proj : network.get_projections())
{
SPDLOG_INFO(
"Running \"{}\" on projection \"{}\".", std::string(validator.second.first),
std::visit([](auto&& proj) { return knp::framework::tags::get_name(proj); }, proj));
auto report = validator.second.second(proj);
log_report(report);
reports.push_back({validator.first, validator.second.first, std::move(report)});
}
}
SPDLOG_INFO("Finished projection validators.");
}

if (network_validators_.size())
{
SPDLOG_INFO("Starting network validators.");
for (auto& validator : network_validators_)
{
SPDLOG_INFO("Running \"{}\".", std::string(validator.second.first));
auto report = validator.second.second(network);
log_report(report);
reports.push_back({validator.first, validator.second.first, std::move(report)});
}
SPDLOG_INFO("Finished network validators.");
}

return reports;
}

} // namespace knp::framework::network_validation
Loading
Loading