Core Interface#
-
class ISample#
Abstract Sample interface definition.
Subclassed by visionflow::LazySample, visionflow::Sample
Public Functions
-
virtual const std::map<ToolNodeId, std::string> &property_types() const = 0#
Get the property name-type name.
- Returns:
std::map<ToolNodeId, std::string> const& The property name-type map.
-
virtual const std::string &property_type(const ToolNodeId &property_name) const = 0#
Get the property type specified by the name.
- Parameters:
property_name – The property name.
- Returns:
std::string The property type.
-
virtual bool exist_property_name(const ToolNodeId &property_name) const = 0#
Check if the property name is valid or not in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property name is valid, otherwise false.
-
virtual bool exist_property_data(const ToolNodeId &property_name) const = 0#
Check if property data exists in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property data exists, otherwise false.
-
virtual const std::shared_ptr<props::IProperty> &get(const ToolNodeId &property_name) const = 0#
Get the property specified by the name.
This function will return nullptr if the property data is not set, or an exception will be thrown if the property name is invalid.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property.
Set the property data specified by the name.
Note
The property data will not be copied, any change to the property data will be reflected in the sample after the call.
- Parameters:
property_name – The property name.
property – The property data. The property data must be the same type as the property type.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
excepts::PropertyTypeMismatch – The type of the property data is not the same as the property type in the sample.
-
virtual std::shared_ptr<props::IProperty> &get_or_create(const ToolNodeId &property_name) = 0#
Get the property data specified by the name. Different from get, If the property data is not set, this function will try to create the property data by the property type.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual std::shared_ptr<props::IProperty> &recreate(const ToolNodeId &property_name) = 0#
Create a new property object specified by the property_name. This method will clean the property data and create a new empty one.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual SampleDescriptor &descriptor() = 0#
Get the sample descriptor.
- Returns:
SampleDescriptor& The sample descriptor.
-
virtual const SampleDescriptor &descriptor() const = 0#
Get the sample descriptor.
- Returns:
SampleDescriptor const& The sample descriptor.
-
virtual const std::map<ToolNodeId, std::string> &property_types() const = 0#
-
class Sample : public visionflow::ISample#
Sample is a collection of data that meet one of the definition of sample properties, a sample contains its own ID, input images and all the output data obtained by the input images after the tool processing.
Public Functions
-
explicit Sample(std::map<ToolNodeId, std::string> property_name_types)#
Construct a new Sample object with the property name-type map.
- Parameters:
property_name_types – The property name-type map.
-
virtual const std::map<ToolNodeId, std::string> &property_types() const override#
Get the property name-type name.
- Returns:
std::map<ToolNodeId, std::string> const& The property name-type map.
-
virtual const std::string &property_type(const ToolNodeId &property_name) const override#
Get the property type specified by the name.
- Parameters:
property_name – The property name.
- Returns:
std::string The property type.
-
virtual bool exist_property_name(const ToolNodeId &property_name) const override#
Check if the property name is valid or not in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property name is valid, otherwise false.
-
virtual bool exist_property_data(const ToolNodeId &property_name) const override#
Check if property data exists in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property data exists, otherwise false.
-
virtual const std::shared_ptr<props::IProperty> &get(const ToolNodeId &property_name) const override#
Get the property specified by the name.
This function will return nullptr if the property data is not set, or an exception will be thrown if the property name is invalid.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Returns:
std::shared_ptr<props::IProperty> The property.
Set the property data specified by the name.
Note
The property data will not be copied, any change to the property data will be reflected in the sample after the call.
- Parameters:
property_name – The property name.
property – The property data. The property data must be the same type as the property type.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
excepts::PropertyTypeMismatch – The type of the property data is not the same as the property type in the sample.
-
PropVisitor operator[](const ToolNodeId &property_name)#
Get or set the property data specified by the name.
- Parameters:
property_name – The property name.
- Returns:
PropVisitor The property visitor, through which you can get or set the property data.
-
virtual std::shared_ptr<props::IProperty> &get_or_create(const ToolNodeId &property_name) override#
Get the property data specified by the name. Different from get, If the property data is not set, this function will try to create the property data by the property type.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual std::shared_ptr<props::IProperty> &recreate(const ToolNodeId &property_name) override#
Create a new property object specified by the property_name. This method will clean the property data and create a new empty one.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual SampleDescriptor &descriptor() override#
Get the sample descriptor.
- Returns:
SampleDescriptor& The sample descriptor.
-
virtual const SampleDescriptor &descriptor() const override#
Get the sample descriptor.
- Returns:
SampleDescriptor const& The sample descriptor.
-
class PropVisitor#
Visitor to help to get or set property with subscript operator.
-
explicit Sample(std::map<ToolNodeId, std::string> property_name_types)#
-
class LazySample : public visionflow::ISample#
LazySample has the following features: It will cache the property data that has been read, written, and queried through it, so as to improve the efficiency of data reading, writing, and querying. (note: If the data in sample has been modified by other means in the meantime, it may cause a data out-of-sync problem).
Public Functions
-
virtual const std::map<ToolNodeId, std::string> &property_types() const override#
Get the property name-type name.
- Returns:
std::map<ToolNodeId, std::string> const& The property name-type map.
-
virtual const std::string &property_type(const ToolNodeId &property_name) const override#
Get the property type specified by the name.
- Parameters:
property_name – The property name.
- Returns:
std::string The property type.
-
virtual bool exist_property_name(const ToolNodeId &property_name) const override#
Check if the property name is valid or not in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property name is valid, otherwise false.
-
virtual bool exist_property_data(const ToolNodeId &property_name) const override#
Check if property data exists in the sample.
- Parameters:
property_name – The property name.
- Returns:
bool True if the property data exists, otherwise false.
-
virtual const std::shared_ptr<props::IProperty> &get(const ToolNodeId &property_name) const override#
Get the property specified by the name.
This function will return nullptr if the property data is not set, or an exception will be thrown if the property name is invalid.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property.
Set the property data specified by the name.
Note
The property data will not be copied, any change to the property data will be reflected in the sample after the call.
- Parameters:
property_name – The property name.
property – The property data. The property data must be the same type as the property type.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
excepts::PropertyTypeMismatch – The type of the property data is not the same as the property type in the sample.
-
virtual std::shared_ptr<props::IProperty> &get_or_create(const ToolNodeId &property_name) override#
Get the property data specified by the name. Different from get, If the property data is not set, this function will try to create the property data by the property type.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual std::shared_ptr<props::IProperty> &recreate(const ToolNodeId &property_name) override#
Create a new property object specified by the property_name. This method will clean the property data and create a new empty one.
- Parameters:
property_name – The property name.
- Throws:
excepts::DataNotFound – The property name not exist in the sample.
- Returns:
std::shared_ptr<props::IProperty> The property data.
-
virtual SampleDescriptor &descriptor() override#
Get the sample descriptor.
- Returns:
SampleDescriptor& The sample descriptor.
-
virtual const SampleDescriptor &descriptor() const override#
Get the sample descriptor.
- Returns:
SampleDescriptor const& The sample descriptor.
-
const std::map<ToolNodeId, std::shared_ptr<props::IProperty>> &cached_properties() const#
Get all cached properties.
- Returns:
NO_DISCARD const&
-
uint32_t id() const#
Get the sample id of the LazySample.
- Returns:
NO_DISCARD
-
virtual const std::map<ToolNodeId, std::string> &property_types() const override#
-
struct SampleDescriptor#
Sample descriptor to describe the sample’s attributes, including tags, created time, etc.
-
class Project#
Project is a unit of work and data management built to complete an actual defect inspect process. A project contains the process pipeline and data such as backup data and report data created for that stream.
Public Functions
-
ProjectDescriptor descriptor() const#
Get the descriptor of the project.
- Returns:
-
void set_remark(const std::string &remark)#
Set the remark of the project.
- Parameters:
remark – The remark of the project.
- Throws:
excepts::LogicError – The project is opened with ProjectOpenMode::kReadOnly.
-
std::string add_tool(const std::string &tool_type, const std::string &tool_id = "")#
Add a new tool into the stream graph.
- Parameters:
tool_type – The type of the tool to be added.Available tool_type is offered by ToolFactory
tool_id – The id of the tool to be added. It should be unique in the stream graph if you want to name it, otherwise an excepts::ToolAlreadyExist will be thrown. Or you can use the default argument (an empty string) to let the system generate a unique id automatically.
- Throws:
excepts::InvalidToolType – If the tool type is not found.
excepts::ToolAlreadyExist – If the tool id is already used.
- Returns:
The id of the tool added.
-
std::string copy_tool(const std::string &origin_tool_id, const std::string ©_tool_id = "", const graph::CopyToolOptions ©_tool_options = {false, {}})#
Copy a tool from the stream graph and add it into the stream graph.
If CopyToolOptions.auto_connect == false, it will only copy the data content and break the link with the stream graph. As a stand alone tool only.
If CopyToolOptions.auto_connect == true, it will automatically connect to the stream graph along the original tool connection according to the CopyToolOptions.tool_maps relationship.
CopyToolOptions.tool_maps does not require the same type of tool, as long as it can be connected.
- Parameters:
origin_tool_id – Original tool id.
copy_tool_id – Copy tool id. If empty,
_copy
will be added to origin_tool_id. Multiple copies will be followed by a number.copy_tool_options – Copy tool options.
- Throws:
visionflow::excepts::InvalidToolId – If origin_tool_id is empty.
visionflow::excepts::ToolNotFound – If tool id dose not exist.
visionflow::excepts::ToolAlreadyExist – If the tool id is already used.
- Returns:
std::string The real tool id of the copy_tool_id.
-
std::map<std::string, std::string> copy_tool_group(const std::set<std::string> &origin_tools, const graph::CopyToolOptions ©_tool_options = {false, {}})#
Copy multiple tools from the stream graph and add them into the stream graph.
If CopyToolOptions.auto_connect == false, it will only copy the data content and break the link with the stream graph. As a stand alone tool only one by one.
If CopyToolOptions.auto_connect == true, it will automatically connect to the stream graph along the original tool connection according to the CopyToolOptions.tool_maps relationship.
For tools that plan copies in origin_tools, the copied tool mapping relationships are automatically added to CopyToolOptions.tool_maps.
CopyToolOptions.tool_maps does not require the same type of tool, as long as it can be connected.
See also
- Parameters:
origin_tools – Original tool ids.
copy_tool_options – Copy tool options.
- Throws:
visionflow::excepts::InvalidToolId – If origin_tool_id is empty.
visionflow::excepts::ToolNotFound – If tool id dose not exist.
visionflow::excepts::ToolAlreadyExist – If the tool id is already used.
- Returns:
std::map<std::string, std::string> The real tool ids of the copy tool ids.
-
void connect(const ToolNodeId &upstream, const ToolNodeId &downstream)#
Connect two tools together by connecting the output data anchor of the first tool (from_tool) to the input data anchor of the second tool (to_tool).
To connect two tools, You must follow the following rules:
The two tools must have been added into the stream graph before, and The output data anchor and input data anchor should be exist in the first tool and the second tool respectively. otherwise excepts::ToolNotFound or excepts::NodeNotFound will be thrown.
The two tools should have different ids, and there is no direct or indirect connection from the second tool to the first tool, otherwise an excepts::LoopConnection will be thrown.
The connect type of the output data anchor of the first tool must be an output data node of the tool, and the input data anchor of the second tool must be a virtual input port, and the two nodes must be data nodes, otherwise an excepts::InvalidConnection will be thrown. see DataEdge::is_tool_output and DataEdge::is_virtual_port() for more details.
the provided features of the output data anchor of the first tool should be matched the required features of the input data anchor of the second tool, and the output data anchor of the first tool and the input data anchor of the second tool should have same cpt_tag, otherwise an excepts::DataTypeMismatch will be thrown.
An output data anchor of a tool can connect to multiple input data anchors of other tools, but an input data anchor can only be connected to a single output data anchor. So it will be reset and reconnected if the input data anchor is already connected to another output data anchor and no exception is thrown.
ToolNodeId is a class that contains tool_id and node_id.
Note
Idempotence. Making multiple identical call has the same effect as making a single call. To add new connection for multi_input node, you can pass a ToolNodeId without index to downstream. And to change an exist connection, you can pass a ToolNodeId contains index to downstream to specify the port to reconnection.
- Parameters:
upstream – The ToolNodeId of the output data anchor to be connected.
downstream – The ToolNodeId of the input data anchor to be connected.
- Throws:
excepts::ToolNotFound – If any tool id is not found.
excepts::NodeNotFound – If any data anchor of the tool is not found.
excepts::LoopConnection – If there already exists a connection from the upstream to the downstream.
excepts::InvalidConnection – If the output data anchor of the first tool is not tool output node, or the input data anchor of the second tool is not a virtual input port.
excepts::DataTypeMismatch – If provided features of the output data anchor of the first tool do not satisfy required features of the input data anchor of the second tool,or the output data anchor of the first tool and the input data anchor of the second tool should have different cpt_tag.
excepts::InActiveOutputNode – Throws if the downstream is an inactive tool output data node.
-
void disconnect(const ToolNodeId &upstream, const ToolNodeId &downstream)#
Disconnect the output node upstream and the virtual input node downstream. The downstream with or without index are both ok. But if downstream contains index, its redirect must be matched with the upstream, otherwise, excepts::InvalidNodeId wil be thrown.
- Parameters:
upstream – The ToolNodeId of the output data anchor to be disconnected.
downstream – The ToolNodeId of the input data anchor to be disconnected.
- Throws:
excepts::ToolNotFound – If tool id is not found.
excepts::NodeNotFound – If any data anchor of the tool is not found.
excepts::InvalidConnection – If node_id of downstream is not a virtual input port.
excepts::InvalidNodeId – If the redirect to of downstream is not matched with the upstream.
-
void disconnect(const ToolNodeId &downstream)#
Disconnect the redirect node specfied by downstream’s index. If downstream has no index, disconnect all the redirects.
Note
if the connection doesn’t exist, no error would occur.
- Parameters:
downstream – a ToolNodeId object specifying the node
- Throws:
excepts::ToolNotFound – If tool id is not found.
excepts::NodeNotFound – If any data anchor of the tool is not found.
excepts::InvalidConnection – If node_id of downstream is not a virtual input port.
-
void remove_tool(const std::string &tool_id, bool remove_all_depends_on_this = false)#
Remove tool. All connections related to the tool will be disconnected.If no such a tool in stream graph, no error would occur.
- Parameters:
tool_id – The id of the tool to be removed.
remove_all_depends_on_this – If true, all the tools that depends on the tool to be removed will be removed as well, default is false.
-
void rename_tool(const std::string &old_tool_id, const std::string &new_tool_id)#
Rename the tool.
- Parameters:
old_tool_id – The old id of the tool.
new_tool_id – The new id of the tool.
- Throws:
excepts::InvalidToolId – If the old_tool_id or new_tool_id is empty.
excepts::ToolNotFound – If the tool named old_tool_id does not exist.
excepts::ToolAlreadyExist – If the tool named new_tool_id already exists. After rename tool, the mapping relationship between property name and column family in database will be updated, and three exceptions may be thrown:
visionflow::excepts::DatasetNotExists – If there is no mapping relationship between the property named and the column family.
visionflow::excepts::DatasetAlreadyExists – If the mapping between the new property name and the column family already exists.
visionflow::excepts::RocksDBError – If the property descriptor fails to read or write to the database.
-
ToolInfo tool_info(const std::string &tool_id) const#
Get the tool info object according to tool id.
- Parameters:
tool_id – Identifier of the tool added to project
- Throws:
excepts::ToolNotFound – If the tool id is not found.
- Returns:
-
std::vector<std::string> tool_list() const#
Get the all tools added to project.
- Returns:
std::vector<std::string> Identifiers of tools
-
ToolNodeId real_id(const ToolNodeId &node_id) const#
The redirect to node id of the virtual node, or itself for others.
- Parameters:
node_id – ToolNodeId specifying the node of the tool.
- Throws:
excepts::ToolNotFound – The tool does not exist in the graph.
excepts::NodeNotFound – The node does not exist in the graph.
excepts::InvalidConnection – The virtual node is not redirected.
- Returns:
ToolNodeId The real id of the node.
-
std::map<ToolNodeId, std::string> all_properties_name_type() const#
Get the name and type of all properties in SampleSet.
- Returns:
a map with pair of property name and property type
-
std::vector<std::string> sample_sets_names() const#
Get names of all sample sets.
- Returns:
std::vector<std::string> all sampleset names in this project
-
void add_sample_set(const std::string &name)#
Add a new sampleset into project.
- Throws:
excepts::DatasetAlreadyExists – If name is empty or a sampleset with specified name already exists
- Parameters:
name –
-
SampleSet get_sample_set(const std::string &name)#
Get sampleset with specified name.
Note
SampleSet keep the reference of data in the project, therefore it should never be used beyond the lifetime of Project.
- Parameters:
name – name of sampleset
- Throws:
excepts::DatasetNotExists – if no such a sampleset
- Returns:
SampleSet
-
ReadOnlySampleSet get_readonly_sample_set(const std::string &name) const#
Get ReadonlySampleSet which include all samples of the project.
Note
ReadOnlySampleSet keep the reference of data in the project, therefore it should never be used beyond the lifetime of Project.
- Parameters:
name – name of sampleset
- Throws:
excepts::DatasetNotExists – if no such a sampleset
- Returns:
ReadOnlySampleSet
-
std::string main_sample_set_name() const#
Get the main sampleset name.
- Returns:
std::string name
-
SampleSet main_sample_set()#
Get the main sampleset.
See also
- Returns:
SampleSet The main sample set, which is owned by the project, and should not be called after the project is closed.
-
ReadOnlySampleSet readonly_main_sample_set() const#
Get the read-only main sampleset.
- Returns:
ReadOnlySampleSet The read-only main sample set, which is owned by the project, and should not be called after the project is closed.
-
void rename_sampleset(const std::string &old_name, const std::string &new_name)#
Rename sampleset.
- Parameters:
old_name –
new_name –
-
void remove_sample_set(const std::string &name)#
remove sampleset and the data in it will be unrecoverable
Note
main sampleset is not allowed to remove
- Throws:
excepts::LogicError – Can not remove main dataset
- Parameters:
name –
-
ConfigureRuntime create_config_runtime(const ToolNodeId &tool_node, const runtime::RuntimeStrategyOptions &strategy_options)#
Create a config runtime object.
- Parameters:
tool_node – The tool_node_id of the configurator.
strategy_options – RuntimeStrategyOptions options specified by users.
- Returns:
-
Runtime create_runtime(const visionflow::runtime::IStrategy &strategy)#
Create a runtime object.
- Parameters:
strategy – RuntimeStrategy which specify the scope to be executed in stream graph.
- Returns:
-
void set_param(const ToolNodeId &tool_node, const visionflow::param::IParameter ¶m)#
Set the param object.
- Parameters:
tool_node – ToolNodeId specifying the node of the tool
param –
-
visionflow::Buffer get_context(const ToolNodeId &tool_node) const#
Get the context object.
- Parameters:
tool_node – ToolNodeId specifying the node of the tool
- Returns:
-
void set_context(const ToolNodeId &tool_node, const visionflow::Buffer &context)#
Set the context object.
- Parameters:
tool_node – ToolNodeId specifying the node of the tool
context – the node context
-
std::shared_ptr<visionflow::param::IParameter> get_param(const ToolNodeId &tool_node) const#
Get the param object of specified tool and node.
- Parameters:
tool_node – ToolNodeId specifying the node of the tool
- Returns:
std::shared_ptr<visionflow::param::IParameter>
-
bool param_exist(const ToolNodeId &tool_node) const#
Check whether the parameter exists.
- Parameters:
tool_node – ToolNodeId specifying the node of the tool
- Throws:
excepts::NodeNotFound – If the node id is not found or the node is not a parameter node.
excepts::ToolNotFound – The tool does not exist in the graph.
excepts::InvalidConnection – If it is a virtual node that is not redirect to.
- Returns:
Returns true if the data exists, false otherwise.
-
std::vector<std::string> backup_names() const#
Get all backup names.
- Returns:
std::vector<std::string> The name of backups.
-
BackupDescriptor get_backup_descriptor(const std::string &backup_name) const#
Get the backup information specified by the backup name.
- Parameters:
backup_name – The name of the backup.
- Throws:
excepts::BackupNotExists – If the backup specified by the backup name does not exist.
- Returns:
BackupDescriptor The backup information.
-
void set_backup_remark(const std::string &backup_name, const std::string &remark)#
Set the remark of the backup.
- Parameters:
backup_name – The name of the backup.
remark – The remark of the backup.
- Throws:
excepts::BackupNotExists – If the backup named ‘backup_name’ does not exist.
-
std::string create_backup(const std::string &backup_name = "", const std::string &remark = "")#
Make an overall backup of the Project.
- Parameters:
backup_name – The name of the backup version. If empty, the current timestamp will be used as the name by default.
remark – The remark of the backup version.
- Throws:
excepts::BackupAlreadyExists – If the backup named ‘backup_name’ already exists.
excepts::FileSystemError – If fail to create backup directory, or the ‘.vfpro’ file can not be opened.
excepts::BadMemoryAlloc – If fail to create backup directory.
excepts::LogicError – If no write permission.
excepts::CanNotOpenFile – If failed to open the backup ‘vflow~graph.vfbin’.
excepts::SerializeFailed – If failed to serialize stream graph.
excepts::RocksDBError – If BackupEngine fails to initialize or fails to create a version backup.
- Returns:
std::string The name of the backup version.
-
void restore_backup(const std::string &backup_name)#
Restore a version backup and all its associated data.
- Parameters:
backup_name – The ID of the backup version.
- Throws:
excepts::BackupNotExists – If the backup_name is not exist.
excepts::LogicError – If no write permission.
excepts::FileSystemError – If the .vfpro file can not be opened, or failed to overwrite the current tool graph with the backup tool graph.
excepts::FileNotFound – If the backup ‘vflow~graph.vfbin’ does not exist.
excepts::CanNotOpenFile – If failed to open the backup ‘vflow~graph.vfbin’.
excepts::DeSerializeFailed – If failed to parse tool graph.
-
void remove_backup(const std::string &backup_name)#
Remove the version backup and all its associated data.
- Parameters:
backup_name – The name of the backup version.
- Throws:
excepts::LogicError – If no write permission.
excepts::FileSystemError – If the .vfpro file can not be opened.
excepts::FileSystemError – IF fail to remove backup directory.
excepts::BadMemoryAlloc – IF fail to remove backup directory.
-
void export_model(const std::string &export_file_path, const std::string &password = "")#
Export the model and parameters.
- Parameters:
export_file_path – Destination path of the exported file,the file suffix of export_path must be .vfmodel.
password – Password for decompressing the exported file. This password is empty by default.
- Throws:
excepts::FileSystemError – IF fail to create tmp directory or the export file.
excepts::FileExisted – If the file already exists.
-
void activate_tool_output(const ToolNodeId &tool_node_id)#
Set a tool output data node as a active node.
- Parameters:
tool_node_id – ToolNodeId of the tool output data node.
- Throws:
excepts::ToolNotFound – If the tool id is not found.
excepts::NodeNotFound – If the node id is not found.
excepts::DataTypeMismatch – If the node is not a tool output node.
-
void deactivate_tool_output(const ToolNodeId &tool_node_id, bool force = false)#
Set a tool output data node as an inactive node.
Note
Exception will be thrown when the tool output data node has been connected already and the user does not mean to force deactivate it. And if the user deactivate it forcefully, all connection redirects this tool output data node will be disconnected.
- Parameters:
tool_node_id – ToolNodeId of the tool output data node.
force – Whether to force deactivate if the tool output data node has been connected already.
- Throws:
excepts::ToolNotFound – If the tool id is not found.
excepts::NodeNotFound – If the node id is not found.
excepts::DataTypeMismatch – If the node is not a tool output node.
excepts::OutputNodeHasBeenUsed – If the node has been connected already but the user does not deactivate it forcefully.
-
std::string to_graphviz(const graph::DotInfoOptions &info_option = {}) const#
Convert the project’s StreamGraph to a dot-language string.
- Parameters:
info_option – The options of dot language node detail info to be showed.
- Returns:
std::string The process graph describe with Graphviz dot language
Public Static Functions
-
static bool Exists(const ProjectDescriptor &proj_desc)#
Check whether a project exists.
- Parameters:
proj_desc – the project descriptor
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
- Returns:
true
- Returns:
false
-
static bool Closed(const ProjectDescriptor &proj_desc)#
Check if project closed normally.
- Parameters:
proj_desc – the project descriptor.
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
excepts::ProjectNotExists – No such a project.
- Returns:
true
- Returns:
false
-
static bool ReadProjectDescriptorFromProject(ProjectDescriptor &proj_desc)#
Read the ProjectDescriptor.
- Parameters:
proj_desc – project descriptor with workspace_token as project_name specified
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
excepts::ProjectNotExists – No such a project.
- Returns:
true if Project exist and proj_desc field will update with project information
- Returns:
false Fail to read project information, and proj_desc won’t update
-
static ProjectDescriptor Create(const ProjectDescriptor &proj_desc)#
Create project.
- Parameters:
proj_desc – Descriptor specifying the parent path and name of the project
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
excepts::ProjectAlreadyExists – The project already existed
- Returns:
ProjectDescriptor of created project (not open yet)
-
static std::unique_ptr<Project> Open(const ProjectDescriptor &proj_desc, ProjectOpenMode open_mode = ProjectOpenMode::kNormally)#
The project can be opened in different modes.
There are a few things to note when opening the project. 1.When a project is opened normally, only one user is allowed to open the project at the same time. 2.When a project is opened in read-only mode,multiple users can read the project data at the same time. 3.When a project is opened in force-write mode, you can open a project with a lock,but not a project in use.
- Parameters:
proj_desc – project descriptor specify the parent path and name of the project
open_mode – The project can be opened in different modes. The default mode is kNormally.
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
excepts::ProjectNotExists – No such a project.
- Returns:
std::unique_ptr<Project>
-
static std::unique_ptr<Project> Open(const std::string &proj_path, ProjectOpenMode open_mode = ProjectOpenMode::kNormally)#
Open Project with project path. The project can be opened in different modes.
There are a few things to note when opening the project. 1.When a project is opened normally, only one user is allowed to open the project at the same time. 2.When a project is opened in read-only mode,multiple users can read the project data at the same time. 3.When a project is opened in force-write mode, you can open a project with a lock,but not a project in use.
- Parameters:
proj_path – The project path, should include the “.vflow” suffix.
open_mode – The project can be opened in different modes. The default mode is kNormally.
- Throws:
excepts::InvalidArgument – The project descriptor is invalid,
excepts::ProjectNotExists – No such a project.
- Returns:
std::unique_ptr<Project> the project handle.
-
ProjectDescriptor descriptor() const#
-
class Model#
The Model interface to open and vfmodel file and create visionflow::Runtime from it. For convenience, it also supports modifying some simple parameters in the model file and re-saving the model.
Public Functions
-
explicit Model(const std::string &path, const std::string &password = "")#
Construct a new Model object with model path and password.
- Throws:
excepts::FileNotFound – If the model file path does not exist.
excepts::InvalidArgument – If the file path is not a file or the file suffix is not .vfmodel.
excepts::CanNotOpenFile – If the model file cannot be opened.
- Parameters:
-
Runtime create_runtime(const visionflow::runtime::IStrategy &strategy)#
Create a runtime object.
- Parameters:
strategy – RuntimeStrategy which specify the scope to be executed in stream graph.
- Returns:
-
std::shared_ptr<param::IParameter> get_param(const ToolNodeId &tool_node) const#
Get the param object of specified tool and node.
See also
- Parameters:
tool_node – ToolNodeId specifying the node of the tool.
- Returns:
std::shared_ptr<visionflow::param::IParameter>
-
void set_param(const ToolNodeId &tool_node, const visionflow::param::IParameter ¶m)#
Set the param object.
See also
- Parameters:
tool_node – ToolNodeId specifying the node of the tool.
param – the parameter type.
-
visionflow::Buffer get_context(const ToolNodeId &tool_node) const#
Get the context object.
See also
- Parameters:
tool_node – ToolNodeId specifying the node of the tool.
- Returns:
-
void set_context(const ToolNodeId &tool_node, const visionflow::Buffer &context)#
Set the context object.
See also
- Parameters:
tool_node – ToolNodeId specifying the node of the tool.
context – the node context.
-
void resave_to(const std::string &path, const std::string &password = "")#
Re-save the model file to another path.
See also
- Parameters:
path – New path(utf-8 encoding) to the model file.
password – New password for model file.
-
explicit Model(const std::string &path, const std::string &password = "")#
-
class WorkSpace#
Public Functions
-
explicit WorkSpace(const std::string &token)#
WorkSpace unique constructor.
See also
- Parameters:
token – The token of the workspace (cloud: URL, local: directory), should be UTF-8 encoding.
- Throws:
excepts::InvalidArgument – Th workspace token is invalid,
excepts::FileSystemError – For the local workspace: folder does not exist and failed to create.
excepts::PermissionError – For the local workspace: no read and write permissions, or it is a system folder.
-
std::string token() const#
Get the token of the workspace.
- Returns:
std::string The token of the workspace.
-
std::string name() const#
Get the name of the workspace.
- Returns:
std::string The name of the workspace.
-
void rename(const std::string &new_name)#
Rename the workspace.
See also
- Parameters:
new_name – The new name of the workspace.
- Throws:
excepts::InvalidArgument – The workspace name is invalid,
excepts::WorkSpaceAlreadyExists – Local: The workspace already exists.
excepts::FileSystemError – Local: if rename the workspace failed.
-
std::string sub_workspace_token(const std::string &sub_workspace_name) const#
Get sub-workspace token by name.
See also
- Parameters:
sub_workspace_name – The name of the sub-workspace.
- Throws:
excepts::InvalidArgument – The workspace name is invalid,
- Returns:
std::string The token of the sub-workspace.
-
std::vector<std::string> sub_workspace_names() const#
Get all first-level sub-workspace names.
- Returns:
std::vector<std::string> The names of first-level sub-workspace.
-
std::string create_sub_workspace(const std::string &sub_workspace_name)#
Create a first-level sub-workspace.
See also
- Parameters:
sub_workspace_name – The name of the sub-workspace to be created.
- Throws:
excepts::InvalidArgument – The workspace name is invalid,
excepts::FileSystemError – Local: if fails to create.
excepts::BadMemoryAlloc – Local: if fails to create.
excepts::SubWorkSpaceAlreadyExists – If the sub-workspace already exists.
- Returns:
std::string The name of the sub-workspace.
-
void remove_sub_workspace(const std::string &sub_workspace_name)#
Remove a first-level sub-workspace.
See also
Note
If the name is empty or does not exist, nothing will be done.
- Parameters:
sub_workspace_name – The name of the sub-workspace to be removed.
- Throws:
excepts::InvalidArgument – The workspace name is invalid,
excepts::FileSystemError – Local: if fails to remove all.
excepts::BadMemoryAlloc – Local: if fails to remove all.
-
std::vector<ProjectDescriptor> project_descriptors() const#
Get all first-level project descriptors of the WorkSpace.
-
ProjectDescriptor create_project(const std::string &project_name, const std::string &project_remark = "")#
Create a new project and return project description information.
See also
- Parameters:
project_name – The name of the project.
project_remark – The remark of the project, empty by default.
- Throws:
excepts::InvalidArgument – The project name is invalid,
excepts::ProjectAlreadyExists – The project already existed.
- Returns:
ProjectDescriptor The descriptor of the project.
-
std::unique_ptr<Project> open_project(const std::string &project_name, ProjectOpenMode pro_open_mode = ProjectOpenMode::kNormally)#
Open an existing project.
See also
Note
There are a few things to note when opening the project. 1.When a project is opened normally, only one user is allowed to open the project at the same time. 2.When a project is opened in read-only mode,multiple users can read the project data at the same time. 3.When a project is opened in force-write mode, you can open a project with a lock,but not a project in use.
- Parameters:
project_name – The name of the project.
pro_open_mode – The project can be opened in different modes, kNormally by default.
- Throws:
excepts::InvalidArgument – The project name is invalid,
excepts::ProjectNotExists – The name of the project does not exist.
- Returns:
std::unique_ptr<Project>
-
void remove_project(const std::string &project_name)#
Remove the project.
See also
Note
If the name is empty or does not exist, nothing will be done.
- Parameters:
project_name – The name of the project.
- Throws:
excepts::InvalidArgument – The project name is invalid,
excepts::ProjectLockExist – If the project is not in a normal closing state.
excepts::FileSystemError – Local: if fails to remove all.
excepts::BadMemoryAlloc – Local: if fails to remove all.
Public Static Functions
-
static void CreateWorkSpace(const std::string &token)#
Create a new WorkSpace.
See also
- Parameters:
token – The token of the workspace (cloud: URL, local: directory), should be UTF-8 encoding.
- Throws:
excepts::InvalidArgument – The workspace name is invalid,
excepts::FileExisted – Local: the directory already exists.
excepts::FileSystemError – Local: The token of the workspace doesn’t exist and failed to create.
excepts::PermissionError – Local: no read and write permissions, or it is a system folder.
-
static void RemoveWorkSpace(const std::string &token)#
Remove the specified WorkSpace.
See also
Note
If the token is empty or does not exist, nothing will be done.
- Parameters:
token – The token of the workspace (cloud: URL, local: directory), should be UTF-8 encoding.
- Throws:
excepts::InvalidArgument – It workspace token is invalid,
excepts::FileSystemError – Local: if fail to remove the files in the WorkSpace.
-
static void MoveWorkSpace(const std::string &from_ws_token, const std::string &to_ws_token)#
Perform an overall move for the WorkSpace.
See also
ProjectDescriptor::IsValidWorkSpaceToken, or move the workspace to its subdirectory.
Note
There are four cases: 1.local to local, 2.local to cloud, 3.cloud to cloud, 4.cloud to local.
- Parameters:
from_ws_token – The token of the source workspace.
to_ws_token – The token of the target workspace.
- Throws:
excepts::InvalidArgument – The from_ws_token or to_ws_token is invalid
excepts::WorkSpaceNotExists – The source workspace does not exist.
excepts::WorkSpaceAlreadyExists – The target workspace already exists.
excepts::FileSystemError – The files move fails.
-
static void CopyWorkSpace(const std::string &from_ws_token, const std::string &to_ws_token)#
Perform an overall copy for the WorkSpace.
See also
ProjectDescriptor::IsValidWorkSpaceToken, or copy the workspace to its subdirectory.
Note
There are four cases: 1.local to local, 2.local to cloud, 3.cloud to cloud, 4.cloud to local.
- Parameters:
from_ws_token – The token of the source workspace.
to_ws_token – The token of the target workspace.
- Throws:
excepts::InvalidArgument – The from_ws_token or to_ws_token is invalid
excepts::WorkSpaceNotExists – The source workspace does not exist.
excepts::WorkSpaceAlreadyExists – The target workspace already exists.
excepts::FileSystemError – The files copy fails.
-
static void CopyProject(const ProjectDescriptor &from_project_descriptor, const ProjectDescriptor &to_project_descriptor)#
Perform an overall copy for the project.
See also
ProjectDescriptor::IsValidProjectDescriptor, or copy the project to its subdirectory.
Note
There are four cases: 1.local to local, 2.local to cloud, 3.cloud to cloud, 4.cloud to local.
- Parameters:
from_project_descriptor – Descriptor of the source project.
to_project_descriptor – Descriptor of the target project.
- Throws:
excepts::InvalidArgument – It the from_project_descriptor or to_project_descriptor is not a valid project description
excepts::ProjectNotExists – The source project does not exist.
excepts::ProjectAlreadyExists – The target project already exists.
excepts::ProjectLockExist – The source project is not in a normal closing state.
excepts::FileSystemError – The files copy fails.
-
static void MoveProject(const ProjectDescriptor &from_project_descriptor, const ProjectDescriptor &to_project_descriptor)#
Perform an overall move for the project.
See also
ProjectDescriptor::IsValidProjectDescriptor, or move the project to its subdirectory.
Note
There are four cases: 1.local to local, 2.local to cloud, 3.cloud to cloud, 4.cloud to local.
- Parameters:
from_project_descriptor – Descriptor of the source project.
to_project_descriptor – Descriptor of the target project.
- Throws:
excepts::InvalidArgument – If the from_project_descriptor or to_project_descriptor is not a valid project description
excepts::ProjectNotExists – The source project does not exist.
excepts::ProjectAlreadyExists – The target project already exists.
excepts::ProjectLockExist – The source project is not in a normal closing state.
excepts::FileSystemError – The files move fails.
-
explicit WorkSpace(const std::string &token)#
-
struct ProjectDescriptor#
-
Public Members
-
std::string workspace_token#
The workspace token which you can get with WorkSpace::token()
-
std::string project_name#
project name.
-
std::string remark#
User-defined project information which users can use it to express any project-related descriptive information.
-
std::string sdk_version#
SDK version used last time to open the project. This field is readonly and can only be set by the sdk, which means it’s not useful if you set it when you create a project.
-
int64_t created_time#
Time stamp when the project was created. This field is readonly and can only be set by the sdk, which means it’s not useful if you set it when you create a project.
-
int64_t last_modified_time#
The last modification timestamp of the project.
-
std::vector<visionflow::Image> brief_images#
Part of sample image for display.
Public Static Functions
-
static bool IsValidWorkSpaceToken(const std::string &token)#
A valid workspace token needs to meet the following conditions: 1.can’t be empty, 2.can’t start or end with a null character, 3.can’t contain the following special characters: {‘*’, ‘?’, ‘”’, ‘<’, ‘>’, ‘|’}.
- Parameters:
token –
- Throws:
excepts::InvalidArgument – If the token is invalid.
- Returns:
true
- Returns:
false
-
static bool IsValidProjectName(const std::string &name)#
A valid project name needs to meet the following conditions: 1.can’t be empty, 2.can’t start or end with a null character, 3.can’t contain the following special characters: {’', ‘/’, ‘:’, ‘*’, ‘?’, ‘”’, ‘<’, ‘>’, ‘|’}, 4.can’t exceed 200 characters in length.
- Parameters:
name –
- Throws:
excepts::InvalidArgument – If the project name is invalid.
- Returns:
true
- Returns:
false
-
static bool IsValidWorkSpaceName(const std::string &name)#
A valid workspace name needs to meet the following conditions: 1.can’t be empty, 2.can’t start or end with a null character, 3.can’t contain the following special characters: {’', ‘/’, ‘:’, ‘*’, ‘?’, ‘”’, ‘<’, ‘>’, ‘|’}, 4.can’t exceed 200 characters in length.
- Parameters:
name –
- Throws:
excepts::InvalidArgument – If the workspace name is invalid.
- Returns:
true
- Returns:
false
-
static bool IsValidProjectDescriptor(const ProjectDescriptor &pro_desc)#
A valid project descriptor needs to meet the following conditions: 1.the project name in the project descriptor is valid.
See also
IsValidProjectName, 2. the workspace token in the project descriptor is valid
See also
- Parameters:
pro_desc –
- Throws:
excepts::InvalidArgument – If the project descriptor is invalid.
- Returns:
true
- Returns:
false
-
std::string workspace_token#
-
struct BackupDescriptor#
Backup version info.
-
enum visionflow::ProjectOpenMode#
Supports different modes to open the project.
Values:
-
enumerator kNormally = 0#
The project is opened normally, and the project data can be read and written.
-
enumerator kReadOnly = 1#
The project is opened in read-only mode, and the project data can only be read.
-
enumerator kForceWrite = 2#
The project is opened in force-write mode,and the project with the lock can be opened.
-
enumerator kNormally = 0#
-
class DataEdge#
DataEdge interface class.
A tool consists of nodes and edges. The edges are the data flow between nodes, and the nodes are the data processing units. Our data would be two types of data: parameters used to configure the data processing units, and properties of a Sample generated by the data processing units.
See also
Public Types
Public Functions
-
std::string id() const#
Get data id in the tool.
- Returns:
std::string The data id.
-
bool is_virtual_port() const#
Get If the data edge is a virtual input port.
- Returns:
true if the data edge is a virtual input port.
- Returns:
false if the data edge is not a virtual input port.
-
size_t allow_max_connect() const#
Get the allowed max connect number of the virtual input port. 1 will be returned if the data edge is not a virtual input port.
- Returns:
size_t
-
std::vector<std::string> required_features() const#
Feature names this virtual input port required. Only data type provided the required features can connects to this port. If the data edge is not a virtual input port, an empty vector will be returned.
- Returns:
std::vector<std::string> the required features.
-
std::vector<ToolNodeId> redirects() const#
Get the data edge’s source node id if the data edge is a “virtual
input” data edge.
This function is only valid when the data edge is a “virtual
input” data edge and the “virtual input” data edge has been connected to a “output” data edge in another tool. If the data edge is not a “virtual
input” data edge, you will get an empty vector, and if the data edge is a “virtual input” but not connected to any “output” data edge in another tool, you will get both empty tool id and empty data id.
- Returns:
std::vector<ToolNodeId> The source tool node id.
-
std::string type() const#
Get the data type of the data edge. Only work when the data node is not a virtual input port.
Note
No meaning to get Virtual input nodes’ type.
- Returns:
std::string The type of the data edge.
-
int64_t last_update_time() const#
Get last modified time of the data edge under the current Environment system configurations. Only work when the data node is not a virtual input port.
See also
Note
No meaning to get Virtual input nodes’ update time.
- Throws:
excepts::DataNotFound – Throws if the current environment system’s configuration not match any environments of context stored in Graph.
- Returns:
int64_t The last modified time of the data edge in utc timestamp.
-
DataCptTag cpt_tag() const#
Get concept type of the data edge, which can be a parameter or a property.
See also
- Returns:
DataCptTag The concept type of the data edge.
-
bool is_tool_output() const#
Get the connect type of the data edge.
- Returns:
True if this data node is one of the tool ouput node.
-
std::vector<ComputeNode> generated_by() const#
Get compute nodes that can generate the given data edge.
Note
As the data edge may be generated by multiple compute nodes although only one compute node will be executed at the same time, the size of the returned vector is not guaranteed to be 1. But in most cases, it is 1.
- Returns:
std::vector<ComputeNode> Compute nodes that can generate the given data edge. An empty vector will be returned if the data edge is a virtual input port.
-
std::vector<ComputeNode> used_by() const#
Get compute nodes that use the given data edge.
Note
As the data edge may be used by multiple compute nodes, the size of the returned vector is not guaranteed to be 1.
- Returns:
std::vector<ComputeNode> Compute nodes that use the given data edge.
-
bool is_active() const#
Check whether a data edge is active or inactive. Only work when the data node is not a virtual input port.
Active means it can be used by its downstream virtual_input data while inactive means it cannot be used by other nodes.
Note
No meaning to get Virtual input nodes’ is_active status.
- Returns:
bool if this data node is active of not.
-
std::string id() const#
-
class ComputeNode#
ComputeNode Info.
Compute nodes are the core data processing units in the tool. a compute node will receive parameters and properties generated by other compute nodes and process the data to generate new parameters or properties.
See also
Public Types
Public Functions
-
std::string id() const#
Get compute node id in the tool. The compute node id is unique in a tool.
- Returns:
std::string The compute node id.
-
std::string type() const#
Get the compute node type of the compute node.
- Returns:
std::string The type of the compute node.
-
int64_t last_update_time() const#
Get last modified time of the compute node in utc timestamp under the current Environment system configurations.
- Throws:
excepts::DataNotFound – Throws if the current environment system’s configuration not match any environments of context stored in Graph.
- Returns:
int64_t The last modified time of the compute node in utc timestamp.
-
std::vector<DataEdge> param_nodes() const#
Get parameter edges required by the compute node.
Note
The parameter edges are the data edges that are used to configure the compute node.
- Returns:
std::vector<DataNode> The parameter edges required by the compute node, all concept type of the data edges returned are kParam.
-
std::vector<DataEdge> input_nodes() const#
Get property and parameter edges required by the compute node.
See also
- Returns:
std::vector<DataEdge> The property and parameter edges required by the compute node.
-
std::vector<DataEdge> output_nodes() const#
Get data edges generated by the compute node.
The data edges are the data edges that are generated by the compute node. If the compute node is a configurator, the generated data edges are parameters. If the compute node is an operator, the generated data edges are properties.
- Returns:
std::vector<DataEdge> The data edges generated by the compute node. All concept type of the data edges returned are kParam or kProp according to the compute node’s concept type.
-
ComputeCptTag cpt_tag() const#
Get the compute node’s concept type.
- Returns:
ComputeCptTag The concept type of the compute node.
-
std::string id() const#
-
class ToolInfo#
ToolInfo is a class that provides information about the tool.
Public Functions
-
std::string id() const#
Get tool id in the tool graph.
- Returns:
std::string The tool id.
-
std::string type() const#
Get the tool type of the tool graph.
- Returns:
std::string The type of the tool.
-
std::vector<DataEdge> input_edges() const#
Get virtual input data edges of the tool.
- Returns:
std::vector<DataEdge> virtual input data edges of the tool.
-
std::vector<DataEdge> output_edges() const#
Get output data edges of the tool.
- Returns:
std::vector<DataEdge> output data edges of the tool. All the connect type of the data edges returned are tool output data edges.
-
std::vector<DataEdge> data_edges() const#
Get all data edges, include the internal, output data and the virtual input nodes in the tool.
- Returns:
std::vector<DataEdge> All data edges in the tool.
-
std::vector<ComputeNode> compute_nodes() const#
Get all compute nodes in the tool.
- Returns:
std::vector<ComputeNode> All compute nodes in the tool.
-
std::string id() const#
-
class ToolNodeId#
Public Functions
-
ToolNodeId(std::string tool_id, std::string node_id, int index = -1)#
Construct a new Tool Node Id object with tool name and node name.
- Parameters:
tool_id – Tool name.
node_id – Node name, which should not contains ‘/’ and brackets. For example: “node_name” or “node_name_1” is valid, “node_name/foo” or “node_name[1]” is invalid.
index – Index suffix number, default -1 means no index suffix.
- Throws:
visionflow::excepts::InvalidNodeId – If the node name is invalid.
-
ToolNodeId(const std::string &concat_id)#
Construct a new Tool Node Id object with concatenated tool name and node name with ‘/’.
- Parameters:
concat_id – Tool name and node name concatenated with ‘/’.
-
const std::string &tool_id() const#
Get the tool name.
- Returns:
const std::string&
-
const std::string &node_id() const#
Get the node name. If has index return node name with index enclosed in brackets at the end.
- Returns:
std::string
-
bool has_index() const#
Get if the node name has index suffix (index >= 0).
- Returns:
true If the node name has index suffix.
- Returns:
false If the node name has no index suffix.
-
int index() const#
Get the index suffix number.
- Returns:
int The index suffix number, return -1 if the node name has no index suffix.
-
ToolNodeId strip_index() const#
Get the ToolNodeId with no index suffix.
- Returns:
ToolNodeId with no index suffix.
-
std::string concat_id() const#
Get the concatenated tool name and node name with ‘/’. If has index return concatenated name with index enclosed in brackets at the end.
- Returns:
std::string
-
std::string full_id() const#
Get the full node name with tool name and index suffix enclosed in brackets if has index.
- Returns:
std::string The full node name with tool name and index suffix.
-
ToolNodeId operator[](int index) const#
Get another ToolNodeId with the given index suffix.
- Parameters:
index – The suffix index number to be set.
- Returns:
ToolNodeId with index suffix.
Public Static Functions
-
static bool IsValidNodeId(const std::string &node_id, std::string *err_msg = nullptr)#
Check if the node name is valid.
- Parameters:
node_id – Node name.
err_msg – Error message if the node name is invalid, otherwise empty.
- Returns:
true If the node name is valid.
- Returns:
false If the node name is invalid.
-
ToolNodeId(std::string tool_id, std::string node_id, int index = -1)#
-
class Runtime#
Runtime handle. It’s used to manage list of operator’s runtime. With this handle, user can inference samples without knowing the graph details of the stream and property details of the sample.
Public Functions
-
Sample create_sample() const#
Create a sample meeting the runtime’s properties requirements.
- Returns:
Sample Created sample.
-
const PropIDTypeMap &required_properties() const#
Get the names and types of all properties required by the runtime.
- Returns:
PropIDTypeMap All properties’s name-type map.
-
const PropIDTypeMap &input_properties() const#
Get the names and types of input properties required by the runtime.
- Returns:
PropIDTypeMap Input properties’ name-type map.
-
const PropIDTypeMap &all_output_properties() const#
Get all output properties’ names and types.
- Returns:
PropIDTypeMap Output properties’ name-type map.
-
const PropIDTypeMap &virtual_output_properties() const#
Get virtual output properties’ names and types.
“Virtual output” means the output property that cannot generate by runtime as the operator to generate it is an virtual operator and can not be run automatically. “Virtual output” should be set into the sample by user before you execute the sample, the virtual operator will only check if it’s meets the parameter requirements and throw an exception if it’s not.
Note
As the virtual output property can not generate by runtime automatically, and user also can not set it without it’s dependency properties which should be generated by runtime automatically, so we stipulate that in a runtime, virtual output properties cannot depend on other output properties, but only on input properties and other virtual properties, otherwise an exception will be thrown when create runtime.
- Returns:
PropIDTypeMap The virtual output properties’s name-type map.
-
const PropIDTypeMap &final_output_properties() const#
Get final output properties’s names and types.
- Returns:
PropIDTypeMap Final output properties’s name-type map.
-
bool is_meeting_requirement(const ISample &sample, std::string *error_message = nullptr) const#
Check if sample meets the runtime’s requirement.
- Parameters:
sample – Sample to be checked.
error_message – [out] Error message if the sample does not meet the runtime requirement. If the sample meets the runtime requirement, this will be an empty string.
- Returns:
bool True if the sample meets the runtime requirement, false if not.
-
void execute(ISample &sample) const#
Inference a sample, generate output properties from input properties in the sample, and check if virtual input properties meets the parameter requirements.
Note
Do not call this function in different threads at the same time.
- Parameters:
sample – [inout] The sample to be inferred, should contains all properties required by the runtime. You can create the sample by calling create_sample and set required input properties into it.
-
Sample create_sample() const#
-
class RuntimeSampleSetAdapter#
Adapter class to adapt a sample set to a runtime.
The adapter will filter out all samples that are not meeting the runtime requirements, and will only read properties that are required by the runtime or write properties output by the runtime. Other properties not related to the runtime will be ignored unless you force write them by calling the update_all_related() method.
Public Types
-
using Iterator = SampleSetRuntimeAdapterIterator#
Iterator type to iterate all samples in the sample set.
Public Functions
-
RuntimeSampleSetAdapter(data::SampleSet *sample_set, const Runtime &runtime)#
-
Iterator begin() const#
Get begin iterator to iterate all samples meeting the runtime’s requirements.
- Throws:
excepts::SampleNotFound – throws if no sample meets the runtime’s requirements.
- Returns:
-
Iterator end() const#
Get end iterator.
- Returns:
const RuntimeSampleSetAdapter::Iterator The SampleSetRuntimeAdapterIterator point to the end of the SampleSet which is an invalid iterator.
-
Sample get(const Iterator &iter) const#
Get the sample where the iterator is pointing to.
This method is only valid when the iterator is pointing to a valid sample, and will only return a sample only contains the input properties required by the runtime. If you want to retrieve the sample with all properties in the sample set, please use get_all_related() instead.
See also
- Parameters:
iter – The iterator to get the sample from.
- Throws:
excepts::SampleNotFound – throws if the iterator is point to an empty sample or the sample does not meet the runtime’s requirements.
- Returns:
Sample The sample where the iterator is pointing to.
-
Sample get(uint32_t id) const#
Get the sample by id.
This method is only valid when the sample id is valid, and will return a sample only contains the input properties required by the runtime. If you want to retrieve the sample with all properties in the sample set, please use get_all_related() instead.
See also
- Parameters:
id – The sample id
- Throws:
excepts::SampleNotFound – throws if the sample with the given id not exist or does not meet the runtime’s requirements.
- Returns:
Sample The sample data of the this id.
Get the sample where the iterator is pointing to.
This method is only valid when the iterator is pointing to a valid sample, and will return a sample contains all properties related to runtime in the graph, which may cause more memory usage and performance loss as the adapter will read all properties of the sample from the database required by runtime. If you only care about the input properties of the runtime, please use get() instead.
See also
- Parameters:
iter – The iterator to get the sample from.
- Throws:
excepts::SampleNotFound – throws if the iterator is point to an empty sample or the sample does not meet the runtime’s requirements.
- Returns:
Sample The sample where the iterator is pointing to.
-
void update(uint32_t id, const ISample &sample)#
Update the sample set’s output properties with the sample.
Note
This function will only save the runtime’s output properties into the sample set, and runtime’s input properties and other un-related properties will not be saved. If you want to save all properties, please use update_all_related() instead.
- Parameters:
id – The ID of the sample in the sample set.
sample – The sample to update the sample set’s properties.
- Throws:
excepts::SampleNotFound – throws if the sample with id not exists in sampleset.
excepts::DataNotFound – throws if the sample has empty property which should be generated by Runtime after executing.
Update the all sample properties in sample set with the sample.
This function will update all sample properties related to the runtime in sample set, which may cause efficiency issues due to reading and writing more data then update. If you can ensure that properties not output by the runtime is not changed, you can use update() instead.
- Parameters:
id – The ID of the sample in the sample set.
sample – The sample to update the sample set’s properties.
- Throws:
excepts::SampleNotFound – throws if the sample with id not exists in sampleset.
visionflow::excepts::RocksDBError – throws if property get or put error occurs.
visionflow::excepts::PropertyTypeMismatch – throws if the property type not matched with DB’s.
-
using Iterator = SampleSetRuntimeAdapterIterator#
-
class SampleSetRuntimeAdapterIterator#
Iterator to iterate all samples meeting the runtime’s requirements in the runtime sample set adapter.
Public Functions
-
bool is_valid() const#
Check if the iterator is pointing to a valid sample.
- Returns:
true If the iterator is pointing to a valid sample.
- Returns:
false If the iterator is not pointing to a valid sample.
-
bool operator==(const SampleSetRuntimeAdapterIterator &other) const#
Check if two iterators point to the same sample.
- Parameters:
other – Another iterator.
- Returns:
true if two iterators point to the same sample.
- Returns:
false if two iterators point to different samples.
-
bool operator!=(const SampleSetRuntimeAdapterIterator &other) const#
Check if two iterators is not point to the same sample.
- Parameters:
other – Another iterator.
- Returns:
true if two iterators point to different samples.
- Returns:
false if two iterators point to the same sample.
-
SampleSetRuntimeAdapterIterator &operator++() noexcept#
Move to next sample meeting the runtime’s requirements.
- Returns:
SampleSetRuntimeAdapterIterator& The iterator after moving.
-
SampleSetRuntimeAdapterIterator operator++(int) noexcept#
Move to next sample meeting the runtime’s requirements.
- Returns:
SampleSetRuntimeAdapterIterator The iterator before moving.
-
SampleSetRuntimeAdapterIterator &operator--() noexcept#
Move to previous sample meeting the runtime’s requirements.
- Returns:
SampleSetRuntimeAdapterIterator& The iterator after moving.
-
SampleSetRuntimeAdapterIterator operator--(int) noexcept#
Move to previous sample meeting the runtime’s requirements.
- Returns:
SampleSetRuntimeAdapterIterator The iterator before moving.
-
uint32_t id() const#
Get Sample ID.
- Throws:
excepts::SampleNotFound – throws if the iterator is point to an empty sample or the sample not meet the runtime’s requirements.
- Returns:
uint32_t The ID of the sample.
-
std::pair<uint32_t, Sample> operator*() const#
Read Sample from data::SampleSet database.
Note
This interface will only read properties required by runtime, so the sample returned would not contain all properties data in the database of the sample but only the input properties.
- Throws:
excepts::InvalidIterator – throws if the iterator is invalid.
excepts::RocksDBError – throws if RocksDB cannot fetch the data.
- Returns:
std::pair<uint32_t, Sample> The ID of the sample and the sample.
-
bool is_valid() const#
-
struct RuntimeStrategyOptions#
The users can indicate their preference for Runtime executing behaviors by configuring RuntimeStrategyOptions.
Public Members
-
bool allow_auto_update = false#
Whether to use auto execute feature when some needed parameter_nodes have not been updated.
-
util::IProgressCallback *call_back = nullptr#
function pointer of Callback in auto-executing process.
-
bool allow_unrealized_oper = false#
Whether to allow unrealized operators exist in runtime. Default set to false.
-
bool ignore_update_time_requirement = false#
Whether to ignore the update status requirement of the nodes. Default set to false.
-
bool allow_auto_update_rely_on_prop = false#
Whether to allow configurators which rely on property execute automatically to update some needed parameter_nodes. Default set to false.
-
bool allow_auto_update = false#
-
class IStrategy#
IStrategy is the information bridge between user and Runtime. The specific sub-class of IStrategy contains two kind of information:
strategy class type (or class name);
the required data to infer the subgraph provided by user;
Subclassed by visionflow::runtime::AllTools, visionflow::runtime::SingleNode, visionflow::runtime::SingleTool, visionflow::runtime::ToolsAndDepends
Public Functions
-
virtual RuntimeStrategyOptions &options() const = 0#
get the strategy options the user set.
- Returns:
RuntimeStrategyOptions strategy options.
-
class SingleTool : public visionflow::runtime::IStrategy#
SingleTool Contains the information to check the execution feasibility construct an Runtime object for the range of a single tool.
Public Functions
-
SingleTool()#
Default constructor.
set the tool_id.
-
SingleTool &set_tool_id(const std::string &tool_id)#
get the tool_id.
-
virtual RuntimeStrategyOptions &options() const override#
get the strategy options the user set.
- Returns:
RuntimeStrategyOptions strategy options.
-
SingleTool()#
-
class SingleNode : public visionflow::runtime::IStrategy#
SingleNode Contains the information to check the execution feasibility construct an Runtime object for the range of a single operator_node.
Public Functions
-
SingleNode()#
Default constructor. A default tool_node_id “DefaultTool/DefaultNode” will be set.
set the tool_node_id of the operator.
-
SingleNode &set_tool_node_id(const ToolNodeId &id)#
get the tool_node_id of the operator.
-
virtual RuntimeStrategyOptions &options() const override#
get the strategy options the user set.
- Returns:
RuntimeStrategyOptions strategy options.
-
SingleNode()#
-
class ToolsAndDepends : public visionflow::runtime::IStrategy#
ToolsAndDepends Contains the information to check the execution feasibility construct an Runtime object for the range of multi-tools and their previous dependence.
Public Functions
-
ToolsAndDepends()#
Default constructor.
set the last tools.
-
ToolsAndDepends &set_tool_ids(const std::unordered_set<std::string> &tool_ids)#
get the last tools.
-
virtual RuntimeStrategyOptions &options() const override#
get the strategy options the user set.
- Returns:
RuntimeStrategyOptions strategy options.
-
ToolsAndDepends()#
-
class AllTools : public visionflow::runtime::IStrategy#
AllTools Strategy allow user construct an Runtime to infer all tools in the graph by setting RuntimeStrategyOptions.
Public Functions
-
AllTools()#
Default constructor.
-
virtual RuntimeStrategyOptions &options() const override#
get the strategy options the user set.
- Returns:
RuntimeStrategyOptions strategy options.
-
AllTools()#
-
using visionflow::PropIDTypeMap = std::map<ToolNodeId, std::string>#
property’s tool_node_id - property’s type
-
using visionflow::PropIDTypeList = std::vector<std::pair<ToolNodeId, std::string>>#
-
class ConfigureRuntime#
Configure Runtime definition.
The ConfigureRuntime class is used to execute a configurator
Public Functions
-
virtual ~ConfigureRuntime() = default#
Destructor.
-
ToolNodeId node_id() const#
Get the configurator node’s ToolNodeId.
- Returns:
ToolNodeId The ToolNodeId of configurator node.
-
std::vector<std::pair<ToolNodeId, std::string>> input_parameters() const#
Get input parameters’ ToolNodeId and types required by the configurator.
- Returns:
std::vector<std::pair<ToolNodeId, std::string>> The parameters’ ToolNodeId and types.
-
std::vector<std::pair<ToolNodeId, std::string>> input_properties() const#
Get input properties’ ToolNodeId and types required by the configurator.
- Returns:
std::vector<std::pair<ToolNodeId, std::string>> The properties’ ToolNodeId and types.
-
std::vector<std::pair<ToolNodeId, std::string>> output_parameters() const#
Get output parameters’ ToolNodeId and types required by the configurator.
- Returns:
std::vector<std::pair<ToolNodeId, std::string>> The output parameters’ ToolNodeId and types.
-
void initialize(const confs::IService &service)#
Initialize the configurator runtime with previous context, input parameters generated by front configurator nodes and required input property set.
See also
- Parameters:
service – provide the initialize data confs::IService
-
TaskStatus execute(confs::IService &service)#
Execute the configurator and generate output parameters and save output parameters and context to service.
See also
- Parameters:
service – store the params generated by the configurator.
- Returns:
TaskStatus The execution status of the ConfigureRuntime. The kAbnormalAbort will be returned if the ConfigRuntime not be initialized before execute.
-
virtual ~ConfigureRuntime() = default#
-
class ConfigProjectImplAdapter : public visionflow::confs::IService#
Adapter for ConfigureRuntime and ProjectImpl.
This class is used to adapt ProjectImpl to ConfigureRuntime.
Subclassed by visionflow::ConfigureRuntimeProjectAdapter
Public Functions
-
void set_progress_callback(util::IProgressCallback *callback)#
Set the progress callback object.
Note
A default callback will execute to logging every 5 seconds if no callback set.
- Parameters:
callback – The pointer of progress callback object, which should be valid during the whole life of the adapter. you should delete the object after the adapter destroyed manually as it’s not managed by the adapter.
-
virtual bool context_exists() const override#
Check if previous context exists or not.
- Returns:
true if previous context exists.
- Returns:
false if previous context not exists.
-
virtual visionflow::Buffer load_context() const override#
Get Context saved after the previous execution, which will be empty if it’s the first execution or the previous execution has not saved any context. You can call context_exists() to check if context exists before get it.
- Returns:
visionflow::Buffer The context buffer saved after the previous execution.
-
virtual void save_context(const Buffer &context) override#
Save current configurator context.
After the configure process success, you can call this method to save current context which maybe useful for the next execution.
- Parameters:
context – The current configurator context.
-
virtual confs::IService::ParamList input_parameters() const override#
Get the input parameters required by the configurator.
- Returns:
confs::IService::ParamList The input parameters required by the configurator.
-
virtual std::vector<const data::IReadOnlyPropertySet*> property_sets() const override#
Get the property set vector required by the configurator.
- Returns:
std::vector<const data::IReadOnlyPropertySet *> The property set vector required by the configurator.
-
virtual void output_parameters(const confs::IService::ParamRefList ¶ms) override#
Save the output parameters generated by the configurator into the project.
- Parameters:
params – The output parameters generated by the configurator.
- Throws:
excepts::ParamListSizeNotMatch – If the size of params is not equal to the size of output_params required by configurator.
-
virtual TaskCtrlSignal on_progress(int total, int progress, const std::string &progress_info) override#
Report the configure process status.
- Parameters:
total – The total number of configure process. You can set total to 0 if you don’t know the total number, and -1 when error happens.
progress – The current progress of the configure process. You should make sure that progress is greater than 0 and less than or equal to total if total is not 0 and -1.
progress_info – The current progress message.
- Throws:
excepts::ProgressNumError – If progress does not meet the requirements.
- Returns:
TaskCtrlSignal Signal to control the task.
-
void set_progress_callback(util::IProgressCallback *callback)#
-
class ConfigureRuntimeProjectAdapter : public visionflow::ConfigProjectImplAdapter#
Adapter for ConfigureRuntime and Project.
This class is used to adapt Project to ConfigureRuntime.
Public Functions
-
ConfigureRuntimeProjectAdapter(Project *project, const ConfigureRuntime &configurator)#
Construct a new ConfigureRuntime Adapter object.
- Parameters:
project – The Project to adapt. You should make sure the project is not nullptr and will not be deleted before the adapter.
configurator – The ConfigureRuntime to adapt to.
-
ConfigureRuntimeProjectAdapter(Project *project, const ConfigureRuntime &configurator)#
-
class ConfigureRuntimeProjectFilterAdapter : public visionflow::confs::IService#
Adapter filter for ConfigureRuntime and ProjectImpl.
This class is used to adapt ProjectImpl to ConfigureRuntime.
Public Functions
-
void set_progress_callback(util::IProgressCallback *callback)#
Set the progress callback object.
Note
A default callback will execute to logging every 5 seconds if no callback set.
- Parameters:
callback – The pointer of progress callback object, which should be valid during the whole life of the adapter. you should delete the object after the adapter destroyed manually as it’s not managed by the adapter.
-
virtual bool context_exists() const override#
Check if previous context exists or not.
- Returns:
true if previous context exists.
- Returns:
false if previous context not exists.
-
virtual visionflow::Buffer load_context() const override#
Get Context saved after the previous execution, which will be empty if it’s the first execution or the previous execution has not saved any context. You can call context_exists() to check if context exists before get it.
- Returns:
visionflow::Buffer The context buffer saved after the previous execution.
-
virtual void save_context(const Buffer &context) override#
Save current configurator context.
After the configure process success, you can call this method to save current context which maybe useful for the next execution.
- Parameters:
context – The current configurator context.
-
virtual confs::IService::ParamList input_parameters() const override#
Get the input parameters required by the configurator.
- Returns:
confs::IService::ParamList The input parameters required by the configurator.
-
virtual std::vector<const data::IReadOnlyPropertySet*> property_sets() const override#
Get the property set vector required by the configurator.
- Returns:
std::vector<const data::IReadOnlyPropertySet *> The property set vector required by the configurator.
-
virtual void output_parameters(const confs::IService::ParamRefList ¶ms) override#
Get the output parameters generated by the configurator. The output parameters will not be automatically saved to the project. If you need to update them to the project, call.
See also
commit to confirm them manually.
- Parameters:
params – The output parameters generated by the configurator.
- Throws:
excepts::ParamListSizeNotMatch – If the size of params is not equal to the size of output_params required by configurator.
-
virtual TaskCtrlSignal on_progress(int total, int progress, const std::string &progress_info) override#
Report the configure process status.
- Parameters:
total – The total number of configure process. You can set total to 0 if you don’t know the total number, and -1 when error happens.
progress – The current progress of the configure process. You should make sure that progress is greater than 0 and less than or equal to total if total is not 0 and -1.
progress_info – The current progress message.
- Throws:
excepts::ProgressNumError – If progress does not meet the requirements.
- Returns:
TaskCtrlSignal Signal to control the task.
-
const std::shared_ptr<param::IParameter> &output_parameter(const ToolNodeId ¶m_name) const#
Get the specified output parameter.
- Parameters:
param_name –
- Throws:
excepts::DataNotFound – No such property set exists.
-
void commit()#
Save the output parameters generated by the configurator and configurator context into the project.
-
void set_filter_ids(const std::vector<uint32_t> &filter_ids)#
The data in filter ids will be filtered out.
- Parameters:
filter_ids –
-
void set_filter_script(const ToolNodeId &property_name, const std::string &filter_script)#
Set the filter script for the specified property.
Note
Have to be aware of that:
It needs to be a complete filter script that conforms to python syntax, and pay attention to indentation.
The name of the function must be ‘vflow_filter’, and there can be only one parameter with any name.
As for the function body, write your filter function, and finally return ‘true’ or ‘false’.
- Parameters:
property_name –
filter_script – Python filter script. eg:
R"( from visionflow.property import * def vflow_filter(data): return data.area() > 2 and data.name() == "test")"
- Throws:
excepts::DataNotFound – No such property set exists.
-
void set_progress_callback(util::IProgressCallback *callback)#
-
class IProgressCallback#
Progress Callback Interface used to notify the progress of the task.
Developers should implement this interface and pass it to the task while executing task to get the progress of the task.
Subclassed by visionflow::util::DefaultProgressCallback
Public Functions
-
virtual TaskCtrlSignal on_progress(int total, int progress, const char *progress_info) = 0#
Call when task status changed.
- Parameters:
total – The total of task, which will be 0 if not known, and -1 if error. The total would change in the middle of task execution.
progress – The progress of task, greater than 0 and less than or equal to total if total is not 0 and -1.
progress_info – The progress message, formatted as json, content format like (Note that not all fields exist in the content):
{ "Loss": { "nacc": 0.704343, "pacc": 0.912434 }, "Time Left": 189.24, "Message": "Some string" }
- Returns:
TaskCtrlSignal The signal to control the task (abort or continue executing).
-
virtual TaskCtrlSignal on_progress(int total, int progress, const char *progress_info) = 0#
-
class DefaultProgressCallback : public visionflow::util::IProgressCallback#
DefaultProgressCallback provides the default on_progress callback function to ConfigureRuntimeProjectAdapter which writes the progress message into log every 5 seconds.
Public Functions
-
virtual TaskCtrlSignal on_progress(int total, int progress, const char *progress_info) override#
Call when task status changed.
- Parameters:
total – The total of task, which will be 0 if not known, and -1 if error. The total would change in the middle of task execution.
progress – The progress of task, greater than 0 and less than or equal to total if total is not 0 and -1.
progress_info – The progress message, formatted as json, content format like (Note that not all fields exist in the content):
{ "Loss": { "nacc": 0.704343, "pacc": 0.912434 }, "Time Left": 189.24, "Message": "Some string" }
- Returns:
TaskCtrlSignal The signal to control the task (abort or continue executing).
-
virtual TaskCtrlSignal on_progress(int total, int progress, const char *progress_info) override#
-
template<typename Meta, typename ConceptType>
class Factory# Factory Template Class.
- Template Parameters:
Meta – The meta information of the concept.
ConceptType – The concept type.
-
template<typename Meta, typename Creator>
class CreatorMutableMixin# Mixin to provide interface to register and unregister creator function.
- Template Parameters:
Meta – The meta information of the concept.
Creator – The creator function.
Subclassed by visionflow::confs::Factory, visionflow::opers::Factory
-
enum class visionflow::TaskStatus#
Task status. This status value is returned at the end of a long-running task to indicate why the task has ended.
Values:
-
enumerator kFinished = 0#
Normal finished.
-
enumerator kAbortByCtrlSignal = 1#
Cancelled by user(caller)
-
enumerator kFinished = 0#
-
enum class visionflow::TaskCtrlSignal#
Signal to control the task. By returning this signal in the progress callback function, the user can control the continuation or abort of the task.
Values:
-
enumerator kContinue = 0#
Continue to run.
-
enumerator kStop = 1#
Stop the task and try to save parameters (trained model) if possible.
-
enumerator kAbort = 2#
Stop task as soon as possible.
-
enumerator kContinue = 0#
-
struct DotInfoOptions#
User-defined node detail info option in dot language.
-
struct CopyToolOptions#
Copy tool options.