DynamicAttributeInterface

class omni.graph.core.DynamicAttributeInterface(port_type: AttributePortType)

Bases: object

Class providing a container for dynamic attribute access interfaces. One of these objects is created per-node, per-port, to contain getter and setter properties on dynamic attributes for their node and port type. These classes persist in the per-node data and their property members are updated based on the addition and removal of dynamic attributes from their node. The base class implementation for the attribute accessors, DynamicAttributeAccess, uses this to determine whether an attribute access request was made on a static or dynamic attribute.

The per-node data on the database will contain one of these objects per port-type. When the database is created it will be attached to the primary attribute access classes via the base class below, DynamicAttributeAccess.

_port_type

Type of port managed by this class (only one allowed per instance). Single underscore only so that the base class of the attribute information can access it.

_element_counts

Dictionary of str:int values which maps the names of dynamic output array attributes to the of pending elements to allocate for their array data (required since Fabric takes the element counter as an argument to the data retrieval so it can’t be set ahead of time). It is set when a size is set, reset when a value is set, and read from Fabric when it’s value is requested. The key values will be the special attribute name that has “_size” appended to it (until such time as the attribute value can support size access itself).

_interfaces

Dictionary of str:og.Attribute values which maps the names of a dynamic attribute to the actual attribute on the node.

_on_gpu

If True then values are requested from the GPU memory, else the CPU memory

_gpu_ptr_kind

Ignored for CPU memory. For GPU memory specifies whether attribute data will be returned as a GPU pointer to the GPU memory, or a CPU pointer to the GPU memory.

Methods

__init__(port_type)

Initialize the namespace used for attributes managed here

add_attribute(new_attribute)

Add in the interface for a newly created attribute.

get(property_name)

Returns the value of the named attribute

has_attribute(property_name)

Returns True if the given property name is a known dynamic attribute on this object

remove_attribute(old_attribute)

Remove the interface for a newly deleted attribute

set(property_name[, locked, new_value])

Sets the value of the named attribute

set_default_memory_location(on_gpu[, ...])

Set the default memory location from which dynamic attribute values will be retrieved.

__init__(port_type: AttributePortType)

Initialize the namespace used for attributes managed here

Parameters

port_type – Port type for the dynamic attribute

add_attribute(new_attribute: Attribute)

Add in the interface for a newly created attribute.

This creates a new attribute on this object named for the new attribute. The value of that attribute is a pair of functions that will get and set the value for that attribute.

Parameters

new_attribute – Attribute that was just added

Raises

og.OmniGraphError – If the attribute has a mismatched port type

get(property_name: str) Any

Returns the value of the named attribute

Parameters

property_name – Name of the property within the namespace of this object’s port type

Returns

Value of the attribute’s data

Return type

Any

Raises

og.OmniGraphError – If the attribute is unknown

has_attribute(property_name: str) bool

Returns True if the given property name is a known dynamic attribute on this object

Parameters

property_name – Name of the property to look for

Returns

True if a dynamic attribute of the given name exists here

Return type

bool

remove_attribute(old_attribute: Attribute)

Remove the interface for a newly deleted attribute

Parameters

old_attribute – Attribute that is about to be removed

Raises

og.OmniGraphError – If the attribute has a mismatched port type, or the property didn’t exist

set(property_name: str, locked: bool = False, new_value: Optional[Any] = None) bool

Sets the value of the named attribute

Parameters
  • property_name – Name of the property within the namespace of this object’s port type

  • locked – True if setting read-only values is currently locked (i.e. inside a compute)

  • new_value – Value to be set on the attribute with the given name

Raises
  • og.OmniGraphError – If the attribute is unknown

  • og.ReadOnlyError – If writing is locked and the attribute is read-only

Returns

True if the value was set

Return type

bool

set_default_memory_location(on_gpu: bool, gpu_ptr_kind: ~omni.graph.core._omni_graph_core.PtrToPtrKind = <PtrToPtrKind.NA: 0>)

Set the default memory location from which dynamic attribute values will be retrieved. This is what will be used if you access dynamic attribute values in the same way you access regular attribute values - e.g. value = db.inputs.dyn_attr.

The settings of the two flags will determine the type of memory returned for array attributes, such as float[], double[3][], and matrixd[4][], and non-array attributes such as int[4], uint, and bool.

Array attributes

on_gpu=True

on_gpu=False

og.PtrToPtrKind.CPU

CPU Pointers to GPU arrays

CPU Pointers to CPU arrays

og.PtrToPtrKind.GPU

GPU Pointers to GPU arrays

CPU Pointers to CPU arrays

og.PtrToPtrKind.NA

GPU Pointers to GPU arrays

CPU Pointers to CPU arrays

Non-Array attributes are always returned as CPU values.

There is currently no supported way of overriding these access methods. If not specified they will default to everything being on the CPU.

Parameters
  • on_gpu – If true then array attributes will be returned from GPU memory, else from CPU memory

  • gpu_ptr_kind – Determines if there is a CPU memory wrapper around the GPU allocated memory, as above.