feat(python): Repaired python bindings
Python bindings have now been brought back up to feature pairity with C++. Further, stubs have been added for all python features so that code completion will work
This commit is contained in:
21
src/python/policy/trampoline/meson.build
Normal file
21
src/python/policy/trampoline/meson.build
Normal file
@@ -0,0 +1,21 @@
|
||||
gf_policy_trampoline_sources = files('py_policy.cpp')
|
||||
|
||||
gf_policy_trapoline_dependencies = [
|
||||
gridfire_dep,
|
||||
pybind11_dep,
|
||||
python3_dep,
|
||||
]
|
||||
|
||||
gf_policy_trampoline_lib = static_library(
|
||||
'policy_trampolines',
|
||||
gf_policy_trampoline_sources,
|
||||
include_directories: include_directories('.'),
|
||||
dependencies: gf_policy_trapoline_dependencies,
|
||||
install: false,
|
||||
)
|
||||
|
||||
gr_policy_trampoline_dep = declare_dependency(
|
||||
link_with: gf_policy_trampoline_lib,
|
||||
include_directories: ('.'),
|
||||
dependencies: gf_policy_trapoline_dependencies,
|
||||
)
|
||||
149
src/python/policy/trampoline/py_policy.cpp
Normal file
149
src/python/policy/trampoline/py_policy.cpp
Normal file
@@ -0,0 +1,149 @@
|
||||
#include "py_policy.h"
|
||||
|
||||
#include "pybind11/pybind11.h"
|
||||
#include "pybind11/stl.h"
|
||||
|
||||
#include "fourdst/atomic/atomicSpecies.h"
|
||||
|
||||
#include "gridfire/reaction/reaction.h"
|
||||
#include "gridfire/engine/engine.h"
|
||||
|
||||
#include "gridfire/policy/policy.h"
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
std::string PyNetworkPolicy::name() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
std::string,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
const std::set<fourdst::atomic::Species>& PyNetworkPolicy::get_seed_species() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const std::set<fourdst::atomic::Species>&,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
get_seed_species
|
||||
);
|
||||
}
|
||||
|
||||
const gridfire::reaction::ReactionSet& PyNetworkPolicy::get_seed_reactions() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const gridfire::reaction::ReactionSet&,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
get_seed_reactions
|
||||
);
|
||||
}
|
||||
|
||||
gridfire::engine::DynamicEngine& PyNetworkPolicy::construct() {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
gridfire::engine::DynamicEngine&,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
construct
|
||||
);
|
||||
}
|
||||
|
||||
gridfire::policy::NetworkPolicyStatus PyNetworkPolicy::get_status() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
gridfire::policy::NetworkPolicyStatus,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
getStatus
|
||||
);
|
||||
}
|
||||
|
||||
const std::vector<std::unique_ptr<gridfire::engine::DynamicEngine>> &PyNetworkPolicy::get_engine_stack() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const std::vector<std::unique_ptr<gridfire::engine::DynamicEngine>> &,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
get_engine_stack
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<gridfire::engine::EngineTypes> PyNetworkPolicy::get_engine_types_stack() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
std::vector<gridfire::engine::EngineTypes>,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
get_engine_types_stack
|
||||
);
|
||||
}
|
||||
|
||||
const std::unique_ptr<gridfire::partition::PartitionFunction>& PyNetworkPolicy::get_partition_function() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const std::unique_ptr<gridfire::partition::PartitionFunction>&,
|
||||
gridfire::policy::NetworkPolicy,
|
||||
get_partition_function
|
||||
);
|
||||
}
|
||||
|
||||
const gridfire::reaction::ReactionSet &PyReactionChainPolicy::get_reactions() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
const gridfire::reaction::ReactionSet &,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
get_reactions
|
||||
);
|
||||
}
|
||||
|
||||
bool PyReactionChainPolicy::contains(const std::string &id) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
bool,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
contains,
|
||||
id
|
||||
);
|
||||
}
|
||||
|
||||
bool PyReactionChainPolicy::contains(const gridfire::reaction::Reaction &reaction) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
bool,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
contains,
|
||||
reaction
|
||||
);
|
||||
}
|
||||
|
||||
std::unique_ptr<gridfire::policy::ReactionChainPolicy> PyReactionChainPolicy::clone() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
std::unique_ptr<gridfire::policy::ReactionChainPolicy>,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
clone
|
||||
);
|
||||
}
|
||||
|
||||
std::string PyReactionChainPolicy::name() const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
std::string,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
uint64_t PyReactionChainPolicy::hash(uint64_t seed) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
uint64_t,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
hash,
|
||||
seed
|
||||
);
|
||||
}
|
||||
|
||||
bool PyReactionChainPolicy::operator==(const ReactionChainPolicy &other) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
bool,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
operator==,
|
||||
other
|
||||
);
|
||||
}
|
||||
|
||||
bool PyReactionChainPolicy::operator!=(const ReactionChainPolicy &other) const {
|
||||
PYBIND11_OVERRIDE_PURE(
|
||||
bool,
|
||||
gridfire::policy::ReactionChainPolicy,
|
||||
operator!=,
|
||||
other
|
||||
);
|
||||
}
|
||||
44
src/python/policy/trampoline/py_policy.h
Normal file
44
src/python/policy/trampoline/py_policy.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
#include "gridfire/policy/policy.h"
|
||||
|
||||
class PyNetworkPolicy final : public gridfire::policy::NetworkPolicy {
|
||||
public:
|
||||
[[nodiscard]] std::string name() const override;
|
||||
|
||||
[[nodiscard]] const std::set<fourdst::atomic::Species>& get_seed_species() const override;
|
||||
|
||||
[[nodiscard]] const gridfire::reaction::ReactionSet& get_seed_reactions() const override;
|
||||
|
||||
[[nodiscard]] gridfire::engine::DynamicEngine& construct() override;
|
||||
|
||||
[[nodiscard]] gridfire::policy::NetworkPolicyStatus get_status() const override;
|
||||
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<gridfire::engine::DynamicEngine>> &get_engine_stack() const override;
|
||||
|
||||
[[nodiscard]] std::vector<gridfire::engine::EngineTypes> get_engine_types_stack() const override;
|
||||
|
||||
[[nodiscard]] const std::unique_ptr<gridfire::partition::PartitionFunction>& get_partition_function() const override;
|
||||
};
|
||||
|
||||
class PyReactionChainPolicy final : public gridfire::policy::ReactionChainPolicy {
|
||||
public:
|
||||
[[nodiscard]] const gridfire::reaction::ReactionSet & get_reactions() const override;
|
||||
|
||||
[[nodiscard]] bool contains(const std::string &id) const override;
|
||||
|
||||
[[nodiscard]] bool contains(const gridfire::reaction::Reaction &reaction) const override;
|
||||
|
||||
[[nodiscard]] std::unique_ptr<ReactionChainPolicy> clone() const override;
|
||||
|
||||
[[nodiscard]] std::string name() const override;
|
||||
|
||||
[[nodiscard]] uint64_t hash(uint64_t seed) const override;
|
||||
|
||||
[[nodiscard]] bool operator==(const ReactionChainPolicy &other) const override;
|
||||
|
||||
[[nodiscard]] bool operator!=(const ReactionChainPolicy &other) const override;
|
||||
};
|
||||
Reference in New Issue
Block a user