Philote-Cpp
C++ bindings for the Philote MDO standard
Loading...
Searching...
No Matches
discipline.h
Go to the documentation of this file.
1/*
2 Philote C++ Bindings
3
4 Copyright 2022-2025 Christopher A. Lupp
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 This work has been cleared for public release, distribution unlimited, case
19 number: AFRL-2023-5716.
20
21 The views expressed are those of the authors and do not reflect the
22 official guidance or position of the United States Government, the
23 Department of Defense or of the United States Air Force.
24
25 Statement from DoD: The Appearance of external hyperlinks does not
26 constitute endorsement by the United States Department of Defense (DoD) of
27 the linked websites, of the information, products, or services contained
28 therein. The DoD does not exercise any editorial, security, or other
29 control over the information you may find at these locations.
30*/
31#pragma once
32
33#include <google/protobuf/struct.pb.h>
34
35#include <map>
36#include <memory>
37#include <variable.h>
38
39#include <data.pb.h>
40#include <disciplines.grpc.pb.h>
41
42namespace philote
43{
44 // forward declaration
45 class DisciplineServer;
46
61 class Discipline : public std::enable_shared_from_this<Discipline>
62 {
63 public:
69
74 ~Discipline() noexcept;
75
81 std::map<std::string, std::string> &options_list();
82
86 std::vector<philote::VariableMetaData> &var_meta() { return var_meta_; }
87 const std::vector<philote::VariableMetaData> &var_meta() const noexcept { return var_meta_; }
88
92 std::vector<philote::PartialsMetaData> &partials_meta() { return partials_meta_; }
93 const std::vector<philote::PartialsMetaData> &partials_meta() const noexcept { return partials_meta_; }
94
100 philote::DisciplineProperties &properties();
101
107 philote::StreamOptions &stream_opts() { return stream_opts_; }
108 const philote::StreamOptions &stream_opts() const noexcept { return stream_opts_; }
109
115 void AddInput(const std::string &name,
116 const std::vector<int64_t> &shape,
117 const std::string &units);
118
124 void AddOutput(const std::string &name,
125 const std::vector<int64_t> &shape,
126 const std::string &units);
127
134 void DeclarePartials(const std::string &f, const std::string &x);
135
142 void AddOption(const std::string &name, const std::string &type);
143
151 virtual void Initialize();
152
159 virtual void Configure();
160
167 virtual void SetOptions(const google::protobuf::Struct &options_struct);
168
174 virtual void Setup();
175
181 virtual void SetupPartials();
182
192 void SetContext(grpc::ServerContext* context) const noexcept;
193
201 void ClearContext() const noexcept;
202
226 bool IsCancelled() const noexcept;
227
228 protected:
242 std::vector<int64_t> ComputePartialShape(const std::string &f,
243 const std::string &x,
244 bool allow_output_as_x);
245
247 std::map<std::string, std::string> options_list_;
248
250 std::vector<philote::VariableMetaData> var_meta_;
251
253 std::vector<philote::PartialsMetaData> partials_meta_;
254
256 philote::DisciplineProperties properties_;
257
259 philote::StreamOptions stream_opts_;
260
262 mutable grpc::ServerContext* current_context_ = nullptr;
263 };
264
265}
Base class for all analysis discipline servers.
Definition discipline_server.h:57
Definition of the discipline base class.
Definition discipline.h:62
philote::StreamOptions & stream_opts()
Gets the stream options.
Definition discipline.h:107
const std::vector< philote::VariableMetaData > & var_meta() const noexcept
Definition discipline.h:87
bool IsCancelled() const noexcept
Check if the current operation has been cancelled.
void SetContext(grpc::ServerContext *context) const noexcept
Set the gRPC server context for cancellation detection.
void AddInput(const std::string &name, const std::vector< int64_t > &shape, const std::string &units)
Declares an input.
virtual void Initialize()
Initialize function that sets up available options.
std::vector< philote::PartialsMetaData > & partials_meta()
Accesses the partials meta data.
Definition discipline.h:92
std::vector< philote::VariableMetaData > var_meta_
List of variable meta data.
Definition discipline.h:250
virtual void Configure()
Configure function that is called after options are set.
const std::vector< philote::PartialsMetaData > & partials_meta() const noexcept
Definition discipline.h:93
philote::StreamOptions stream_opts_
Stream options.
Definition discipline.h:259
Discipline()
Construct a new Discipline object.
philote::DisciplineProperties properties_
Discipline properties.
Definition discipline.h:256
virtual void SetupPartials()
Setup function that is called by the server when the client calls the setup RPC.
philote::DisciplineProperties & properties()
Gets the discipline properties.
void AddOutput(const std::string &name, const std::vector< int64_t > &shape, const std::string &units)
Declares an output.
std::map< std::string, std::string > options_list_
List of options that can be set by the client.
Definition discipline.h:247
void AddOption(const std::string &name, const std::string &type)
Add an option to the discipline.
virtual void SetOptions(const google::protobuf::Struct &options_struct)
Sets up all discipline options based on a protobuf struct that the server received from the client.
void ClearContext() const noexcept
Clear the gRPC server context.
const philote::StreamOptions & stream_opts() const noexcept
Definition discipline.h:108
std::map< std::string, std::string > & options_list()
Gets the options list.
virtual void Setup()
Setup function that is called by the server when the client calls the setup RPC.
std::vector< philote::VariableMetaData > & var_meta()
Accesses the variable meta data.
Definition discipline.h:86
grpc::ServerContext * current_context_
Current gRPC server context for cancellation detection (mutable for const correctness)
Definition discipline.h:262
std::vector< int64_t > ComputePartialShape(const std::string &f, const std::string &x, bool allow_output_as_x)
Computes the shape for a partial derivative df/dx.
void DeclarePartials(const std::string &f, const std::string &x)
Declare a (set of) partial(s) for the discipline.
std::vector< philote::PartialsMetaData > partials_meta_
List of partials meta data.
Definition discipline.h:253
~Discipline() noexcept
Destroy the Discipline object.
Definition discipline.h:43