AttributeManager#
- class omni.graph.tools.ogn.AttributeManager(attribute_name: str, attribute_type_name: str)#
Bases:
object
Base class that provides support methods common to all types of attributes
The members of this class implementing the mandatory values must be named the same as AttributeKeys.MANDATORY
- attribute_type_name#
Role interpretation of the attribute type (e.g. colorf for float[3])
- array_depth#
How many array levels are on this attribute (optional, range 0-2 - default 0)
- base_name#
Name of the attribute with the namespace removed
- cuda_pointer_type#
Location of CUDA array pointers
- default#
Value for the attribute when none is explicitly specified at runtime (mandatory)
- description#
Description of what the attribute does (mandatory)
- do_validation#
Is the attribute required to be valid before compute can be called?
- element_count#
How many members of an array attribute are specified in the default value?
- attribute_type#
Type of attribute this is (INPUT_GROUP, OUTPUT_GROUP, STATE_GROUP)
- is_deprecated#
Has the attribute been deprecated? (optional - default False)
- deprecation_msg#
Optional message describing what users must to do deal with the deprecated attribute
- imports_og#
The list of OmniGraph import statements required by this attribute type
- imports_standard#
The list of Python import statements required by this attribute type
- is_required#
Is the attribute required for the node to operate? (optional - default True)
- manager#
Object created to manage data for this attribute’s type
- memory_type#
Key indicating where the attribute’s memory is stored (optional - default MemoryTypeValues.CPU)
- metadata#
Dictionary of Key/Value strings attached to the attribute (optional - default {})
- name#
Name of the attribute (mandatory)
- namespace#
Namespace of the attribute (split from the full name)
- tuple_count#
How many members of the same type are in this attribute as a tuple? (optional - default 1)
- e.g. float[3] has a tuple count of 3
- type#
Type of data contained by this attribute (mandatory)
- unimplemented_error#
None if attribute is valid, else a string indicating what is unimplemented
- Abstract Methods To Override:
- These methods do not have usable definitions and must be overridden specifically for each attribute type.
cpp_base_type_name(self) -> str cuda_base_type_name(self) -> str python_type_name(self) -> str sdf_type_name(self) -> str usd_name(self) -> str usd_type_name(self) -> str
Usually you can add element counts and arrays using the associated FOO_add_containers() method, however you are free to elevate a type to array and element amounts in any way you like.
- Other Methods To Override:
- These methods add information, and should include the results from the super() call in their result
add_python_imports(self) cpp_includes(self) -> List[str] cpp_element_type_name(self) -> str cuda_includes(self) -> List[str] cuda_element_type_name(self) -> str tuples_allowed(self) -> List[int]
The derived classes must also implement the class variable OGN_TYPE, which defines how the base type of the attribute is declared in the .ogn file (e.g. “float” for float, float[3], float[], etc.)
Methods
__init__
(attribute_name, attribute_type_name)Set up the empty attribute values for population from the JSON description
Add the modules required for proper parsing of this type
Returns a list of array depths supported by the attribute type, by default up to 1 level deep
Returns a human-readable version of the base data type of the attribute
Checks to see if this attribute is currently supported.
Returns True if the accessor constructed for the attribute's data is always on the CPU, else it will be wherever the attribute's memory type dictates.
cpp_add_arrays
(base_type)Common method for transforming a base C++ type to add any appropriate arrays.
Returns a string with the base C++ type of the attribute data
Returns the C++ configuration data that applies to the attribute type implemented by this manager If no implementation is defined then return an empty dictionary.
cpp_constructor_value
(value)Return a string with the Python 'value' translated to the C++ equivalent as an initializer
Return a list of declarations to include in the C++ header for proper compilation of this type This will be included after the declarations.
Returns the current default value of this attribute in a C++-compatible format, None for no default.
Returns a string with the full C++ type of the attribute data
cpp_element_value
(value)Return a string with the simple Python 'value' translated to the C++ equivalent as an initializer.
Returns the extended type identifier for C++ types
Return a list of files to include in the C++ header for proper compilation of this type Note that the list entries should include the <> or "" surrounding the file name so that the proper include can be generated (e.g. '<carb/Types.h>' versus '"../myIncludes/myFile.h"').
Generate the code for the static attribute initializer.
Outputs any attribute-specific code needing to run at the end of the initializeType method
Outputs any attribute-specific code needing to run at the top of in the initializeType method
Returns a string with the role name for this attribute - none by default
cpp_tuple_value
(value)Return a string with the simple Python 'value' translated to the C++ equivalent as an initializer.
Return a list of strings containing the definitions of C++ typedefs facilitating the access of this attribute's Fabric data.
cpp_typedef_name
([use_namespace])Returns a string with the typedef for this attribute's raw type as it appears in Fabric.
cpp_variable_name
([use_namespace])Return the name of the attribute in a form suitable for use as a C++ variable name.
Returns a string with the wrapper class used to access attribute data in the C++ database along with the non-default parameters to that class's template
Returns the type of this attribute as expected by the attribute creation methods
Returns a string with the base C++ type of the attribute data
Returns the C++ configuration data that applies to the attribute type implemented by this manager If no implementation is defined then return an empty dictionary.
Returns a string with the full CUDA type of the attribute element data, not counting arrays
Return a list of include statements to add to the CUDA section of the C++ header The strings should be full paths, like "omni/graph/core/iComputeGraph.h"
Returns a string with the role name for this attribute - none by default
Returns a string with the full CUDA type of the attribute data.
Returns a description of the fully qualified data type - common assembly that applies to many types
Returns a list of declarations used by the datamodel accessor constructor
Returns a string containing the declaration of the datamodel accessor variable for this attribute
emit_usd_declaration
(out)Print a declaration for this attribute in USD
Attribute types must define their single empty value
Returns an empty value compatible with the current attribute type
Returns a string representing the raw data type stored in Fabric for this attribute's default values.
Return a string corresponding to the type of element data this attribute points to in Fabric.
Returns true if the attribute's data type requires a separate element count variable
Return a string that checks for the existence of the fabric pointer variable value
Return a string corresponding to the type of data this attribute points to in Fabric.
generate_python_batched_property_code
(index, out)Emits the generated code implementing a batched property for this attribute.
Emits the generated code implementing a readable property for this attribute.
Adds any code required to validate the value of an attribute before a Python compute method is called
Only regular attribute are subject to auto-conversion, which could prevent them from being vectorized Array attributes are always vectorizable, thus don't have a canVectorize method
Returns True if the attribute's type is fixed at compile time
Returns False: attributes are not dynamic by default
Returns true iff the attribute is a matrix type, where the tuple_count must be squared
Returns True if this attribute should no be written to
Return the C++ version of true/false that tells if this attribute is required
Returns the memory location the attribute's data will be stored - usually the same as its memory type
Returns a string containing the fully expanded name of this attribute type in a .ogn file
Returns a string containing the fully expanded name of this attribute type in a .ogn file, without arrays
ogn_type
()Returns a string containing the fully expanded name of this attribute type in a .ogn file
override_cpp_configuration
(base_type_name, ...)Override the type definitions applicable to the attribute type implemented by this manager.
override_cuda_configuration
(base_type_name, ...)Override the type definitions applicable to the attribute type implemented by this manager.
parse_extra_properties
(property_set)Parse any extra properties specific to certain attribute types
parse_metadata
(metadata)Parse the metadata attached to the attribute type.
python_add_containers
(base_type[, numpy_type])Common method for transforming a base Python type to add any appropriate array or component values
Return the name of a python name that will correspond to this attribute.
Returns the extended type identifier for Python attribute types
Return the name of a python property that will correspond to this attribute.
Returns a string with the role name for this attribute usable in Python code - none by default
Returns a string with the Python annotation name, as defined by the omni.graph.core.types module.
Returns a string with the Python "typing" type-checking declaration for the attribute data
python_value
(value)Returns the value of this attribute in a Python-compatible format, None for no default.
python_value_as_repr
(value)Returns the value of this attribute in a format that prints as something that can be assigned.
python_value_as_str
(value)Returns the value of this attribute in a Python-compatible format, None for no default.
Only array attributes need a pre compute invalidation call
Returns True if this type of attribute needs a default value
sample_values
([for_usd])A set of sample values of the attribute's type for testing - None if samples are not supported.
By default no SDF base type exists
Returns a string with the pxr::SdfValueTypeName of the attribute data
Returns True if this type of attribute can handle metadata output
Return a string with the declaration of a tuple count argument for constructors
Returns a list of tuple numbers supported by the attribute type, by default only single values
usd_add_arrays
(base_type)Common method for transforming a base USD type to add any appropriate array values
usd_add_containers
(base_type)Common method for transforming a base USD type to add any appropriate array or component values
Returns the current default value of this attribute in a USD-compatible format, None for no default.
usd_element
(element[, bare])Get the value of a single USD element as a string (e.g. float, int, string, token.
usd_name
()Returns a string with the name of the attribute in a USD file
Returns a string with the data type the attribute would use in a USD file
usd_value
(value)Returns the current default value of this attribute in a USD-compatible format, None for no default.
validate_configuration
([pedantic])Validate that the current state of the object is legal for use
Check that the default is a legal value, making any implicit changes required to make it so if needed
validate_value
(value)Raises a ParseError if value is not legal value; never happens in the base class
validate_value_nested
(array_data, array_levels)Validate that the given data matches an array of this attribute's type
validate_value_structure
(value_to_validate)Validate a value being set on the attribute.
value_for_test
(value)Returns the value of this attribute in a format suitable for test output, None for no default.
Attributes
CPP_CONFIGURATION
CUDA_CONFIGURATION
OGN_TYPE
- __init__(
- attribute_name: str,
- attribute_type_name: str,
Set up the empty attribute values for population from the JSON description
- Parameters:
attribute_name – Unique name for this attribute
attribute_type_name – Unique name for this attribute type
- add_python_imports()#
Add the modules required for proper parsing of this type
- static array_depths_supported() List[int] #
Returns a list of array depths supported by the attribute type, by default up to 1 level deep
- base_data_type_description() str #
Returns a human-readable version of the base data type of the attribute
- check_support()#
Checks to see if this attribute is currently supported.
This is different from the attribute being valid as this only raises an exception if the attribute is a legal type, it just hasn’t had proper code generation added for it yet.
- Raises:
AttributeError – If any attributes on the node are currently not supported
- cpp_accessor_on_cpu() bool #
Returns True if the accessor constructed for the attribute’s data is always on the CPU, else it will be wherever the attribute’s memory type dictates.
- cpp_add_arrays(base_type: str) str #
Common method for transforming a base C++ type to add any appropriate arrays.
Call this method directly when the tuple type is not the standard std::array
- Parameters:
base_type – String containing the type name of the single-value, e.g. “float”
- cpp_base_type_name() str #
Returns a string with the base C++ type of the attribute data
- cpp_configuration() CppConfiguration #
Returns the C++ configuration data that applies to the attribute type implemented by this manager If no implementation is defined then return an empty dictionary.
- cpp_constructor_value(value) str #
Return a string with the Python ‘value’ translated to the C++ equivalent as an initializer
- This recurses to handle arrays and tuples. For example an array of float[2] would look like this in Python:
[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]
- and this in C++
{{1.0f, 2.0f}, {3.0f, 4.0f}, {5.0f, 6.0f}}
- Parameters:
value – Python value to convert - e.g. True -> “true”, [] -> {}
- Returns:
A string representing the given values in C++ form
- cpp_declarations() List[str] #
Return a list of declarations to include in the C++ header for proper compilation of this type This will be included after the declarations.
- cpp_default_initializer()#
Returns the current default value of this attribute in a C++-compatible format, None for no default.
- cpp_element_type_name() str #
Returns a string with the full C++ type of the attribute data
- cpp_element_value(value) str #
Return a string with the simple Python ‘value’ translated to the C++ equivalent as an initializer. This method assumes the value is not a list, which should be handled in cpp_constructor_value or cpp_tuple_value.
- Parameters:
value – Python value to convert - e.g. True -> “true”
- Raises:
ParseError – The derived classes must override this method to provide a value of the correct format
- cpp_extended_type()#
Returns the extended type identifier for C++ types
- cpp_includes() List[str] #
Return a list of files to include in the C++ header for proper compilation of this type Note that the list entries should include the <> or “” surrounding the file name so that the proper include can be generated (e.g. ‘<carb/Types.h>’ versus ‘”../myIncludes/myFile.h”’)
- cpp_initializer() Tuple[str, str] #
Generate the code for the static attribute initializer.
The initializer contains any compile-time values for the attribute, like name and type name.
- Returns:
- (NAME, DECLARATION)
NAME: Name of the initializer object, which should be file-static DECLRATION: Full declaration of the initializer object
- cpp_post_initialization(
- out: IndentedOutput,
Outputs any attribute-specific code needing to run at the end of the initializeType method
- cpp_pre_initialization(
- out: IndentedOutput,
Outputs any attribute-specific code needing to run at the top of in the initializeType method
- cpp_role_name() str #
Returns a string with the role name for this attribute - none by default
- cpp_tuple_value(value) str #
Return a string with the simple Python ‘value’ translated to the C++ equivalent as an initializer. This method checks to make sure the list elements match the tuple count, if any.
- Parameters:
value – Python value to convert - e.g. True -> “true”
- Raises:
ParseError – The derived classes must override this method to provide a value of the correct format
- cpp_typedef_definitions() List[str] #
Return a list of strings containing the definitions of C++ typedefs facilitating the access of this attribute’s Fabric data. The typedefs returned will vary, based on the memory type of the attribute. The base typedef “X_t” will always refer to the type of data you get from the attribute’s accessor; i.e. the return value from “db.inputs.X()”. The typedef will be an appropriate one for the memory type. For “ANY” member types there will be two typedefs, “X_cpu_t” and “X_gpu_t” indicating the typedefs to use when the data is extracted on the CPU and GPU respectively.
- cpp_typedef_name(use_namespace: bool = True)#
Returns a string with the typedef for this attribute’s raw type as it appears in Fabric. Use this typedef name instead of the raw type to avoid C++’s problem with things like “float[3]&”
- cpp_variable_name(use_namespace: bool = False) str #
Return the name of the attribute in a form suitable for use as a C++ variable name.
No attempt is made to remove the cases where an attribute has a keyword name. That is left up to the calling code if necessary.
- Parameters:
use_namespace – If True then include “inputs:” or “outputs:” as part of the name
- cpp_wrapper_class() Tuple[str, List[str]] #
Returns a string with the wrapper class used to access attribute data in the C++ database along with the non-default parameters to that class’s template
- create_type_name() str #
Returns the type of this attribute as expected by the attribute creation methods
- cuda_base_type_name() str #
Returns a string with the base C++ type of the attribute data
- cuda_configuration() CudaConfiguration #
Returns the C++ configuration data that applies to the attribute type implemented by this manager If no implementation is defined then return an empty dictionary.
- cuda_element_type_name() str #
Returns a string with the full CUDA type of the attribute element data, not counting arrays
- cuda_includes() List[str] #
Return a list of include statements to add to the CUDA section of the C++ header The strings should be full paths, like “omni/graph/core/iComputeGraph.h”
- cuda_role_name() str #
Returns a string with the role name for this attribute - none by default
- cuda_type_name() str #
Returns a string with the full CUDA type of the attribute data. The CUDA type adds an extra pointer indirection because the data is passed through from the CPU, and can not be dereferenced since the memory is on the GPU.
- data_type_description() str #
Returns a description of the fully qualified data type - common assembly that applies to many types
- datamodel_accessor_constructor_args() List[str] #
Returns a list of declarations used by the datamodel accessor constructor
- datamodel_accessor_declaration()#
Returns a string containing the declaration of the datamodel accessor variable for this attribute
- emit_usd_declaration(out) List[str] #
Print a declaration for this attribute in USD
- Parameters:
out – Output handler where the USD will be emitted
- empty_base_value() Any #
Attribute types must define their single empty value
- empty_value() Any #
Returns an empty value compatible with the current attribute type
- fabric_default_data_typedef() str #
Returns a string representing the raw data type stored in Fabric for this attribute’s default values. Uses the predefined raw type for attribute’s whose type requires it (e.g. array of double[3] since “double[3]*” is not a valid type.)
- fabric_element_type() str #
Return a string corresponding to the type of element data this attribute points to in Fabric. This only differs from fabric_raw_type() in that arrays do not get an extra level of indirection.
- fabric_needs_counter() bool #
Returns true if the attribute’s data type requires a separate element count variable
- fabric_pointer_exists() List[str] #
Return a string that checks for the existence of the fabric pointer variable value
- fabric_raw_type() str #
Return a string corresponding to the type of data this attribute points to in Fabric. This is used for size information, in particular for default values and for adding attributes to Fabric so using the C++ type is good enough.
- generate_python_batched_property_code(
- index: int,
- out: IndentedOutput,
Emits the generated code implementing a batched property for this attribute.
The properties are currently only designed to read/write the data from CPU batch.
The code will be a simple property, e.g. “db.inputs.attributeName”:
@property def attributeName(self):
- generate_python_property_code(
- out: IndentedOutput,
Emits the generated code implementing a readable property for this attribute.
The properties will take one of two forms, depending on where the attribute’s memory resides.
- For hardcoded CPU or GPU versions the code will be a simple property, e.g. “db.inputs.attributeName”:
@property def attributeName(self): …
When the memory location is determined at runtime then a secondary level is installed to give access to both as either “db.inputs.attributeName.cpu” or “db.inputs.attributeName.gpu”
- class __attributeName:
@property def cpu(self): … @property def gpu(self): …
- @property
- def attributeName(self):
return __attributeName()
- generate_python_validation(
- out: IndentedOutput,
Adds any code required to validate the value of an attribute before a Python compute method is called
- has_can_vectorize()#
Only regular attribute are subject to auto-conversion, which could prevent them from being vectorized Array attributes are always vectorizable, thus don’t have a canVectorize method
- has_fixed_type() bool #
Returns True if the attribute’s type is fixed at compile time
- is_dynamic()#
Returns False: attributes are not dynamic by default
- classmethod is_matrix_type() bool #
Returns true iff the attribute is a matrix type, where the tuple_count must be squared
- is_read_only() bool #
Returns True if this attribute should no be written to
- is_required_as_string()#
Return the C++ version of true/false that tells if this attribute is required
- memory_storage() str #
Returns the memory location the attribute’s data will be stored - usually the same as its memory type
- ogn_base_type() str #
Returns a string containing the fully expanded name of this attribute type in a .ogn file
- ogn_root_type() str #
Returns a string containing the fully expanded name of this attribute type in a .ogn file, without arrays
- ogn_type() str #
Returns a string containing the fully expanded name of this attribute type in a .ogn file
- override_cpp_configuration(
- base_type_name: str,
- include_files: List[str],
- cast_required: bool,
Override the type definitions applicable to the attribute type implemented by this manager.
- Parameters:
base_type_name (str) – Data type for one of the attribute values (e.g. “double”)
cast_required (bool) – Is a cast required for construction? (e.g. “true” versus “pxr::GfHalf(1.0)”)
include_files (List[str]) – List of files to include to define the above types (e.g. [“pxr/gf/vec3d.h”])
- override_cuda_configuration(
- base_type_name: str,
- include_files: List[str],
- cast_required: bool,
Override the type definitions applicable to the attribute type implemented by this manager.
- Parameters:
base_type_name (str) – Data type for one of the attribute values (e.g. “double”)
cast_required (bool) – If True then a cast is required for construction (e.g. “true” versus “__half(1.0)”)
include_files (List[str]) – List of files to include to define the above types (e.g. [“cuda_fp16.h”])
- parse_extra_properties(
- property_set: dict,
Parse any extra properties specific to certain attribute types
- Parameters:
property_set – (NAME, VALUE) for properties the attribute type might support
- parse_metadata(
- metadata: Dict[str, Any],
Parse the metadata attached to the attribute type. Overrides to this method can add additional interpretation of special metadata.
- python_add_containers(
- base_type: str,
- numpy_type: str = None,
Common method for transforming a base Python type to add any appropriate array or component values
- python_attribute_name() str #
Return the name of a python name that will correspond to this attribute.
The attribute name itself is used as a property to represent the value. This name is for storing the actual og.Attribute.
- python_extended_type()#
Returns the extended type identifier for Python attribute types
- python_property_name() str #
Return the name of a python property that will correspond to this attribute.
Input attributes have a parent object “inputs” and output attributes have a parent object “outputs” in order to avoid name clashes and be consistent with the appearance of the C++ equivalent code
- python_role_name() str #
Returns a string with the role name for this attribute usable in Python code - none by default
- python_type_annotation() str #
Returns a string with the Python annotation name, as defined by the omni.graph.core.types module. The type names are derived from the OGN names since they are already similar. The only difference is that the names reorder a bit to look more like Sdf names since that’s what people will be familiar with.
- python_type_name() str #
Returns a string with the Python “typing” type-checking declaration for the attribute data
- python_value(value)#
Returns the value of this attribute in a Python-compatible format, None for no default.
- python_value_as_repr(value)#
Returns the value of this attribute in a format that prints as something that can be assigned.
- python_value_as_str(value)#
Returns the value of this attribute in a Python-compatible format, None for no default.
- require_precompute_invalidation()#
Only array attributes need a pre compute invalidation call
- requires_default()#
Returns True if this type of attribute needs a default value
- sample_values(for_usd: bool = False) Any #
A set of sample values of the attribute’s type for testing - None if samples are not supported.
- Parameters:
for_usd – If True return as the data type used to set the value in USD attributes, else return Python values Values are returned as a list of constructor arguments; e.g. if a call to set a value looks like this: Set(float, float, float) then the parameters returned would be [float, float, float]
- sdf_base_type() str | None #
By default no SDF base type exists
- sdf_type_name() str #
Returns a string with the pxr::SdfValueTypeName of the attribute data
- supports_metadata() bool #
Returns True if this type of attribute can handle metadata output
- tuple_argument()#
Return a string with the declaration of a tuple count argument for constructors
- static tuples_supported() List[int] #
Returns a list of tuple numbers supported by the attribute type, by default only single values
- usd_add_arrays(base_type: str) str #
Common method for transforming a base USD type to add any appropriate array values
- usd_add_containers(base_type: str) str #
Common method for transforming a base USD type to add any appropriate array or component values
- usd_default_value()#
Returns the current default value of this attribute in a USD-compatible format, None for no default.
- usd_element(element, bare: bool = False) str #
Get the value of a single USD element as a string (e.g. float, int, string, token… no arrays or tuples)
- usd_name() str #
Returns a string with the name of the attribute in a USD file
- usd_type_name() str #
Returns a string with the data type the attribute would use in a USD file
- usd_value(value)#
Returns the current default value of this attribute in a USD-compatible format, None for no default.
- validate_configuration(pedantic: bool = False)#
Validate that the current state of the object is legal for use
- Parameters:
pedantic – If True then be more fussy than usual when checking the configuration
- Raises:
ParseError if the current configuration is missing mandatory information or has illegal values –
- validate_default()#
Check that the default is a legal value, making any implicit changes required to make it so if needed
- Raises:
ParseError – If the default was not a legal value
- validate_value(value)#
Raises a ParseError if value is not legal value; never happens in the base class
This only checks a single value for the attribute type, not things like arrays of values or elements. For those checks call validate_value_structure().
- validate_value_nested(
- array_data: List,
- array_levels: List[int],
Validate that the given data matches an array of this attribute’s type
- Parameters:
array_data – List of data elements to validate.
array_levels – List of number of members allowed in nested arrays. 0 means any number. Until this is [] the members of array_data must themselves be lists.
- Raises:
ParseError if the structure of the data does not match the structure and values of the attribute –
- validate_value_structure(value_to_validate)#
Validate a value being set on the attribute.
This checks to make sure there is a match between the structure of the value and that expected by the attribute type. (e.g that float[3] contains 3 values, all floats). For a single value check that only verifies matching simple data type use validate_value()
- Raises:
ParseError if the value to validate was not compatible with this attribute type –
- value_for_test(value)#
Returns the value of this attribute in a format suitable for test output, None for no default.