Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add correct transfer for is_forcing_ field of impact message: #0000001 #5

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* @kaspersky_support Artiom N.
* @date 21.02.2023
* @license Apache 2.0
* @copyright © 2024 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
* @copyright © 2024 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.
*/

Expand Down Expand Up @@ -131,7 +131,7 @@ void process_inputs(
{
if (impact.synapse_type_ == synapse_traits::OutputType::EXCITATORY)
{
neuron.is_being_forced_ = message.is_forcing_;
neuron.is_being_forced_ |= message.is_forcing_;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* @kaspersky_support Artiom N.
* @date 06.10.2023
* @license Apache 2.0
* @copyright © 2024 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
* @copyright © 2024 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.
*/

Expand Down Expand Up @@ -146,8 +146,8 @@ template <class NeuronType>
neuron_traits::ISIPeriodType update_isi(
neuron_traits::neuron_parameters<neuron_traits::SynapticResourceSTDPNeuron<NeuronType>> &neuron, uint64_t step)
{
if (neuron
.is_being_forced_) // This neuron got a forcing spike this turn and doesn't continue its spiking sequence.
// This neuron got a forcing spike this turn and doesn't continue its spiking sequence.
if (neuron.is_being_forced_)
{
neuron.isi_status_ = neuron_traits::ISIPeriodType::is_forced;
// Do not update last_step_.
Expand Down Expand Up @@ -320,8 +320,8 @@ void do_dopamine_plasticity(
if (step - synapse->rule_.last_spike_step_ < synapse->rule_.dopamine_plasticity_period_)
{
// Change synapse resource.
float d_r = neuron.dopamine_value_ *
std::min(static_cast<float>(std::pow(2, -neuron.stability_)), 1.F) / 1000.0F;
float d_r =
neuron.dopamine_value_ * std::min(static_cast<float>(std::pow(2, -neuron.stability_)), 1.F);
synapse->rule_.synaptic_resource_ += d_r;
neuron.free_synaptic_resource_ -= d_r;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ table SynapticImpactMessage
header: MessageHeader;
presynaptic_population_uid: UID;
postsynaptic_population_uid: UID;
is_forcing: bool;
impacts: [SynapticImpact];
}

Expand Down
16 changes: 9 additions & 7 deletions knp/core-library/impl/messaging/synaptic_impact_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::ostream &operator<<(std::ostream &stream, const SynapticImpact &impact)
std::ostream &operator<<(std::ostream &stream, const SynapticImpactMessage &msg)
{
stream << msg.header_ << " " << msg.postsynaptic_population_uid_ << " " << msg.presynaptic_population_uid_ << " "
<< msg.impacts_.size();
<< static_cast<int>(msg.is_forcing_) << " " << msg.impacts_.size();
for (auto v : msg.impacts_) stream << " " << v;
return stream;
}
Expand All @@ -77,8 +77,11 @@ std::ostream &operator<<(std::ostream &stream, const SynapticImpactMessage &msg)
std::istream &operator>>(std::istream &stream, SynapticImpactMessage &msg)
{
size_t impacts_count = 0;
stream >> msg.header_ >> msg.postsynaptic_population_uid_ >> msg.presynaptic_population_uid_ >> impacts_count;
int forcing_buf;
stream >> msg.header_ >> msg.postsynaptic_population_uid_ >> msg.presynaptic_population_uid_ >> forcing_buf >>
impacts_count;

msg.is_forcing_ = forcing_buf;
if (0 == impacts_count) return stream;

msg.impacts_.resize(impacts_count);
Expand Down Expand Up @@ -112,7 +115,8 @@ ::flatbuffers::uoffset_t pack_internal(::flatbuffers::FlatBufferBuilder &builder
auto pre_synaptic_uid = get_marshaled_uid(msg.presynaptic_population_uid_);
auto post_synaptic_uid = get_marshaled_uid(msg.postsynaptic_population_uid_);

return marshal::CreateSynapticImpactMessageDirect(builder, &header, &pre_synaptic_uid, &post_synaptic_uid, &impacts)
return marshal::CreateSynapticImpactMessageDirect(
builder, &header, &pre_synaptic_uid, &post_synaptic_uid, msg.is_forcing_, &impacts)
.o;
}

Expand All @@ -138,7 +142,6 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg)
UID sender_uid{false};
UID presynaptic_uid{false};
UID postsynaptic_uid{false};
bool is_forced = false;
std::copy(
s_msg_header->sender_uid().data()->begin(), // clang_sa_ignore [core.CallAndMessage]
s_msg_header->sender_uid().data()->end(), // clang_sa_ignore [core.CallAndMessage]
Expand All @@ -150,7 +153,6 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg)

std::vector<SynapticImpact> impacts;
impacts.reserve(s_msg->impacts()->size());

std::transform(
s_msg->impacts()->begin(), s_msg->impacts()->end(), std::back_inserter(impacts),
[](const auto &msg_val)
Expand All @@ -160,9 +162,9 @@ SynapticImpactMessage unpack(const marshal::SynapticImpactMessage *s_msg)
msg_val->connection_index(), msg_val->impact_value(), type, msg_val->presynaptic_neuron_index(),
msg_val->postsynaptic_neuron_index()};
});

bool is_forcing = s_msg->is_forcing();
return SynapticImpactMessage{
{sender_uid, s_msg_header->send_time()}, presynaptic_uid, postsynaptic_uid, is_forced, std::move(impacts)};
{sender_uid, s_msg_header->send_time()}, presynaptic_uid, postsynaptic_uid, is_forcing, std::move(impacts)};
}

} // namespace knp::core::messaging
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ struct neuron_parameters<SynapticResourceSTDPNeuron<NeuronType>> : public neuron
/**
* @brief ISI period status.
*/
ISIPeriodType isi_status_ = ISIPeriodType::period_continued;
ISIPeriodType isi_status_ = ISIPeriodType::not_in_period;

/**
* @brief Last non-forced spike step.
Expand Down
6 changes: 4 additions & 2 deletions knp/tests/core/message_bus_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendZMQ)
{knp::core::UID{}},
knp::core::UID{},
knp::core::UID{},
false,
true,
{{1, 2, synapse_type, 3, 4}, {4, 3, synapse_type, 2, 1}, {7, 8, synapse_type, 9, 10}}};

auto &subscription = ep1.subscribe<SynapticImpactMessage>(knp::core::UID(), {msg.header_.sender_uid_});
Expand All @@ -138,6 +138,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendZMQ)
EXPECT_EQ(msgs[0].header_.sender_uid_, msg.header_.sender_uid_);
ASSERT_EQ(msgs[0].presynaptic_population_uid_, msg.presynaptic_population_uid_);
ASSERT_EQ(msgs[0].postsynaptic_population_uid_, msg.postsynaptic_population_uid_);
ASSERT_EQ(msgs[0].is_forcing_, msg.is_forcing_);
ASSERT_EQ(msgs[0].impacts_, msg.impacts_);
}

Expand All @@ -153,7 +154,7 @@ TEST(MessageBusSuite, SynapticImpactMessageSendCPU)
{knp::core::UID{}},
knp::core::UID{},
knp::core::UID{},
false,
true,
{{1, 2, synapse_type, 3, 4}, {4, 3, synapse_type, 2, 1}, {7, 8, synapse_type, 9, 10}}};

auto &subscription = ep1.subscribe<SynapticImpactMessage>(knp::core::UID(), {msg.header_.sender_uid_});
Expand All @@ -169,5 +170,6 @@ TEST(MessageBusSuite, SynapticImpactMessageSendCPU)
EXPECT_EQ(msgs[0].header_.sender_uid_, msg.header_.sender_uid_);
ASSERT_EQ(msgs[0].presynaptic_population_uid_, msg.presynaptic_population_uid_);
ASSERT_EQ(msgs[0].postsynaptic_population_uid_, msg.postsynaptic_population_uid_);
ASSERT_EQ(msgs[0].is_forcing_, msg.is_forcing_);
ASSERT_EQ(msgs[0].impacts_, msg.impacts_);
}
4 changes: 3 additions & 1 deletion knp/tests/core/messaging_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ TEST(MessageSuite, ImpactToChannelTest)
{
const knp::core::UID uid{true}, pre_uid{true}, post_uid{true};
const size_t time = 7;
const bool forcing = true;
const knp::synapse_traits::OutputType type = knp::synapse_traits::OutputType::DOPAMINE;
const std::vector<knp::core::messaging::SynapticImpact> impacts{{1, 2, type, 3, 4}, {5, 6, type, 7, 8}};

const knp::core::messaging::SynapticImpactMessage message_in{{uid, time}, pre_uid, post_uid, false, impacts};
const knp::core::messaging::SynapticImpactMessage message_in{{uid, time}, pre_uid, post_uid, forcing, impacts};
knp::core::messaging::SynapticImpactMessage message_out;

std::stringstream stream;
Expand All @@ -65,6 +66,7 @@ TEST(MessageSuite, ImpactToChannelTest)
ASSERT_EQ(message_out.header_.send_time_, time);
ASSERT_EQ(message_out.presynaptic_population_uid_, pre_uid);
ASSERT_EQ(message_out.postsynaptic_population_uid_, post_uid);
ASSERT_EQ(message_out.is_forcing_, forcing);
ASSERT_EQ(message_out.impacts_, impacts);
}

Expand Down