Turi Create  4.0
turi::unity_global Class Reference

#include <model_server/lib/unity_global.hpp>

Public Member Functions

 unity_global (toolkit_function_registry *_toolkit_functions, toolkit_class_registry *_classes)
 
std::string get_version ()
 
std::shared_ptr< unity_sgraph_baseload_graph (std::string fname)
 
std::vector< std::string > list_toolkit_classes ()
 
variant_map_type load_model (const std::string &url)
 
void save_model (std::shared_ptr< model_base > tkclass, const variant_map_type &sidedata, const std::string &url)
 
void save_model2 (const std::string &model_name, const variant_map_type &sidedata, const std::string &url)
 
std::vector< std::string > list_toolkit_functions ()
 
std::map< std::string, flexible_typedescribe_toolkit_function (std::string toolkitname)
 
std::map< std::string, flexible_typedescribe_toolkit_class (std::string class_name)
 
std::shared_ptr< model_basecreate_toolkit_class (std::string class_name)
 
toolkit_function_response_type run_toolkit (std::string toolkit_name, variant_map_type &arguments)
 
std::string get_graph_dag ()
 
flexible_type eval_lambda (const std::string &pylambda_string, const flexible_type &arg)
 
flexible_type eval_dict_lambda (const std::string &pylambda_string, const std::vector< std::string > &keys, const std::vector< flexible_type > &args)
 
std::vector< flexible_typeparallel_eval_lambda (const std::string &pylambda_string, const std::vector< flexible_type > &arg)
 
std::string __read__ (const std::string &url)
 
void __write__ (const std::string &url, const std::string &content)
 
bool __mkdir__ (const std::string &url)
 
bool __chmod__ (const std::string &url, short mode)
 
size_t __get_heap_size__ ()
 
size_t __get_allocated_size__ ()
 
void set_log_level (size_t)
 
std::map< std::string, flexible_typelist_globals (bool runtime_modifiable)
 
std::string set_global (std::string key, flexible_type value)
 
std::shared_ptr< unity_sarray_base > create_sequential_sarray (ssize_t size, ssize_t start, bool reverse)
 
std::string load_toolkit (std::string soname, std::string module_subpath)
 
std::vector< std::string > list_toolkit_functions_in_dynamic_module (std::string soname)
 
std::vector< std::string > list_toolkit_classes_in_dynamic_module (std::string soname)
 
std::string get_current_cache_file_location ()
 
toolkit_function_registryget_toolkit_function_registry ()
 
toolkit_class_registryget_toolkit_class_registry ()
 
std::string get_turicreate_object_type (const std::string &url)
 
void model_variant_deep_save (const variant_type &var, oarchive &oarc)
 
void model_variant_deep_load (variant_type &var, iarchive &iarc)
 

Detailed Description

The turi::unity_global and turi::unity_global_base classes implement a singleton object on the server side which is exposed to the client via the cppipc system. This singleton object provides other miscellaneous uncategorized services (global functions) to the python layer.

Definition at line 24 of file unity_global.hpp.

Constructor & Destructor Documentation

◆ unity_global()

turi::unity_global::unity_global ( toolkit_function_registry _toolkit_functions,
toolkit_class_registry _classes 
)

Constructor

Parameters
regPointer to Toolkit registry. Since Unity Global manaages toolkit execution
serverPointer to the comm server object. Toolkit execution status will be emitted there.

Member Function Documentation

◆ __chmod__()

bool turi::unity_global::__chmod__ ( const std::string &  url,
short  mode 
)

Changes permissions of the given url.

◆ __get_allocated_size__()

size_t turi::unity_global::__get_allocated_size__ ( )

Returns the amount of memory used inside the heap. May not be available. Returns 0 if unavailable.

◆ __get_heap_size__()

size_t turi::unity_global::__get_heap_size__ ( )

Returns the size of the process heap. May not be available. Returns 0 if unavailable.

◆ __mkdir__()

bool turi::unity_global::__mkdir__ ( const std::string &  url)

Creates a directory that will have the given url.

Throws exception if directory already exists.

◆ __read__()

std::string turi::unity_global::__read__ ( const std::string &  url)

Reads the content of the given url.

Return a string containing the content of the given url.

Throws exception if IO error occurs.

Note
This function should only be used for internal testing.

◆ __write__()

void turi::unity_global::__write__ ( const std::string &  url,
const std::string &  content 
)

Writes the content of to the given url.

Throws exception if IO error occurs.

Note
This function should only be used for internal testing.

◆ create_sequential_sarray()

std::shared_ptr<unity_sarray_base> turi::unity_global::create_sequential_sarray ( ssize_t  size,
ssize_t  start,
bool  reverse 
)

Create a sequentially increasing (or decreasing) SArray.

If 'reverse' is true, counts down instead of up.

◆ create_toolkit_class()

std::shared_ptr<model_base> turi::unity_global::create_toolkit_class ( std::string  class_name)

Creates a class instance.

◆ describe_toolkit_class()

std::map<std::string, flexible_type> turi::unity_global::describe_toolkit_class ( std::string  class_name)

Returns a dictionary describing the class. It will return a dictionary with 2 fields:

  • "name": The name of the toolkit
  • "functions": A dictionary with key: function name, and value, a list of input parameters.
  • "get_properties": The list of all readable properties of the class
  • "set_properties": The list of all writable properties of the class
  • "documentation"

◆ describe_toolkit_function()

std::map<std::string, flexible_type> turi::unity_global::describe_toolkit_function ( std::string  toolkitname)

Returns a dictionary describing the toolkit. It will return a dictionary with 2 fields:

  • "name": The name of the toolkit
  • "arguments": The list of input parameters
  • "documentation"

◆ eval_dict_lambda()

flexible_type turi::unity_global::eval_dict_lambda ( const std::string &  pylambda_string,
const std::vector< std::string > &  keys,
const std::vector< flexible_type > &  args 
)

Evaluate a pickled python lambda with dictionary argument.

◆ eval_lambda()

flexible_type turi::unity_global::eval_lambda ( const std::string &  pylambda_string,
const flexible_type arg 
)

Evaluate a pickled python lambda with the given argument.

◆ get_current_cache_file_location()

std::string turi::unity_global::get_current_cache_file_location ( )

Retrieve the folder that is currently being used to hold temp files.

This is where all the SFrame files and such are located.

◆ get_graph_dag()

std::string turi::unity_global::get_graph_dag ( )

Internal utility function. Gets the structure of the lazy evaluation dag for the graph operations.

◆ get_toolkit_class_registry()

toolkit_class_registry* turi::unity_global::get_toolkit_class_registry ( )

Returns a pointer to the toolkit class registry

◆ get_toolkit_function_registry()

toolkit_function_registry* turi::unity_global::get_toolkit_function_registry ( )

Returns a pointer to the toolkit function registry

◆ get_turicreate_object_type()

std::string turi::unity_global::get_turicreate_object_type ( const std::string &  url)

Given a url, returns the type of the Turi object, return value could be: model, graph, sframe, sarray

◆ get_version()

std::string turi::unity_global::get_version ( )

Get the version string

◆ list_globals()

std::map<std::string, flexible_type> turi::unity_global::list_globals ( bool  runtime_modifiable)

Lists all the global configuration values. If runtime_modifiable == true, lists all global values which can be modified at runtime. If runtime == false, lists all global values which can only be modified by environment variables.

◆ list_toolkit_classes()

std::vector<std::string> turi::unity_global::list_toolkit_classes ( )

Lists the names of all regsitered classes.

◆ list_toolkit_classes_in_dynamic_module()

std::vector<std::string> turi::unity_global::list_toolkit_classes_in_dynamic_module ( std::string  soname)

Lists all the classes in a toolkit. Raises an exception if the toolkit was not previously loaded by load_toolkit.

◆ list_toolkit_functions()

std::vector<std::string> turi::unity_global::list_toolkit_functions ( )

Lists the names of all registered toolkit functions.

◆ list_toolkit_functions_in_dynamic_module()

std::vector<std::string> turi::unity_global::list_toolkit_functions_in_dynamic_module ( std::string  soname)

Lists all the functions in a toolkit. Raises an exception if the toolkit was not previously loaded by load_toolkit.

◆ load_graph()

std::shared_ptr<unity_sgraph_base> turi::unity_global::load_graph ( std::string  fname)

Constructs a graph from a binary file on disk, or HDFS

◆ load_model()

variant_map_type turi::unity_global::load_model ( const std::string &  url)

Load toolkit class from file.

Returns variant_map varmap

  • varmap['archive_version'] if 0, is the legacy version. 1 is the current version.

Archive version 1:

  • varmap['model_name'] stores the C++ model name. Always available
  • varmap['model'] stores the unity toolkit class object pointer. May not be always available.
  • varmap['side_data'] stores a varmap of any additional side data serialized along with the model. May not be always available.

Legacy:

  • varmap['model_wrapper'] stores the serialized lambda to construct the python class.
  • varmap['model_base'] stores the unity toolkit class object pointer.

Throws an exception if there is an error reading the url or serializing to a proper toolkit class object.

◆ load_toolkit()

std::string turi::unity_global::load_toolkit ( std::string  soname,
std::string  module_subpath 
)

Attempts to load a toolkit from a shared library. Returns an empty string on success. An string describing the error on failure.

The so will be loaded with prefix [module_subpath].[filename].[...] For instance: if the so is called "example.so" containing a function square_root.

load_toolkit("example.so", "")

will load the toolkit function into "example.square_root". (it will also appear in tc.extensions.example.square_root)

load_toolkit("example.so", "pika")

will load the toolkit function "pika.example.square_root". (it will also appear in tc.extensions.pika.example.square_root)

module_subpath can also be ".."

load_toolkit("example.so", "..")

In which case it will appear anywhere except in the top level of tc.extensions as tc.extensions.square_root.

◆ model_variant_deep_load()

void turi::unity_global::model_variant_deep_load ( variant_type var,
iarchive iarc 
)

A alternate implementation of variant_deep_load which knows how to save models. Models are special because they rely on the unity_global registry. Fully compatible with variant_deep_load otherwise.

See also
variant_deep_load

◆ model_variant_deep_save()

void turi::unity_global::model_variant_deep_save ( const variant_type var,
oarchive oarc 
)

A alternate implementation of var which knows how to save models. Models are special because they rely on the unity_global registry. Fully compatible with variant_deep_save otherwise.

See also
variant_deep_save

◆ parallel_eval_lambda()

std::vector<flexible_type> turi::unity_global::parallel_eval_lambda ( const std::string &  pylambda_string,
const std::vector< flexible_type > &  arg 
)

Evaluate a pickled python lambda on a list of argument in parallel.

◆ run_toolkit()

toolkit_function_response_type turi::unity_global::run_toolkit ( std::string  toolkit_name,
variant_map_type &  arguments 
)

Runs a toolkit of the specified name, and with the specified arguments. Returns a toolkit_function_response_type which contains the result of the toolkit execution (success/failure) as well as any additional returned state (graphs/classes/etc). Will throw an exception if the toolkit name was not found.

◆ save_model()

void turi::unity_global::save_model ( std::shared_ptr< model_base tkclass,
const variant_map_type &  sidedata,
const std::string &  url 
)

Save a toolkit class to file.

Parameters
tkclassThe pointer to the actual toolkit class object.
sidedataAny additional side information
urlThe destination url to store the class.

◆ save_model2()

void turi::unity_global::save_model2 ( const std::string &  model_name,
const variant_map_type &  sidedata,
const std::string &  url 
)

Saves a model using an alternative model saving method where a model class is not available.

Parameters
model_nameA unique string name of the model
sidedataAny additional side information
urlThe destination url to store the class.

◆ set_global()

std::string turi::unity_global::set_global ( std::string  key,
flexible_type  value 
)

Sets a modifiable global configuration value. Returns an empty string on success and an error string on failure.

◆ set_log_level()

void turi::unity_global::set_log_level ( size_t  )

Sets the logging level


The documentation for this class was generated from the following file: