.. _ogn_tutorial_state_attributes_py:

Tutorial 17 - Python State Attributes Node
==========================================

This node illustrates how you can use state attributes. These are attributes that are not meant to be connected to
other nodes as they maintain a node's internal state, persistent from one evaluation to the next.

As they are persistent, care must be taken that they be initialized properly. This can take the form of a reset
flag, as seen on this node, state flag values with known defaults that describe the validity of the state attribute
data, or using a checksum on inputs, among other possibilities.

State attributes can be both read and written, like output attributes. The presence of state attributes will also
inform the evaluators on what type of parallel scheduling is appropriate.

These attributes provide a similar functionality to those found in :ref:`ogn_tutorial_state_py`, except that being
node attributes the structure is visible to the outside world, making it easier to construct UI and visualizers for
it.

OgnTutorialStateAttributesPy.ogn
--------------------------------
The *.ogn* file containing the implementation of a node named "omni.graph.tutorials.StateAttributesPy", with a couple of state
attributes that both read and write values during the compute.

.. literalinclude:: OgnTutorialStateAttributesPy.ogn
    :linenos:
    :language: json

OgnTutorialStateAttributesPy.py
-------------------------------
The *.py* file contains the compute method that uses the state attributes to run the algorithm.

.. literalinclude:: OgnTutorialStateAttributesPy.py
    :linenos:
    :language: python


Test Script
-----------
The .ogn test infrastructure currently only supports single evaluation, which will not be sufficient to test state
attribute manipulations. This test script runs multiple evaluations and verifies that the state information is
updated as expected after each evaluation.

.. literalinclude:: ../../python/tests/test_tutorial_state_attributes_py.py
    :linenos:
    :language: python
