krish-adi / barfi

Python Flow Based Programming environment that provides a graphical programming environment.
https://barfi.readthedocs.io
MIT License
672 stars 73 forks source link

Enhancement Request: Support for self.get_blockname #5

Closed zabrewer closed 2 years ago

zabrewer commented 2 years ago

For user error messages (i.e. which block failed) and other uses

krish-adi commented 2 years ago

How would you use this? Could you give me an example usage?

zabrewer commented 2 years ago

Sure. One of the use cases is that the compute blocks go one by one and if there is a non-standard error that is not captured in logging for the app itself, streamlit, or another library the user never sees see what block was executing. Once the execute button is run, everything just kind of runs in the background...

Here's one example.

At the top of the page, initiate a streamlit placeholder with st.empty(). This is overly simplified but should get the point across... The user gets a streamlit info message at the top of the page for every block when it is executing.

execution_block_placeholder = st.empty()

# begin compute engine functions
def my_compute_engine(self):
    # compute logic for input_block_1
    block_name = self.get_blockname(self) # <--- need to think through this, we don't know the name of the block
    block_execution_message = f('Now executing block {block_name}')
    execution_execution_block_placeholder.info(block_execution_message)
   # we could also have warning, error and other messages here and either re-use execution_block_message 
   # OR add a new placeholder e.g. warning_block_placeholder = st.empty

input_block_1 = Block(name='Input Block 1')
input_block_1 .add_input(name='Save Orgs and Networks to Local Cache')
input_block_1 .add_compute(my_compute_engine)
zabrewer commented 2 years ago

@krish-adi - I don't know if this should be filed under a new enhancement req or this one but it would be nice to also get the last block or have an array where we could say block X of Y blocks. Case is to notify the user of which block is currently running and to let them know when all blocks have run successfully (or not). Some blocks may take some time to run with large API datasets. If something goes wrong, need to know where and notify the user in addition to internally with logger.

krish-adi commented 2 years ago

In v 0.7.0, now each block can store a private state. This state can store anything you want to access after execution. All the errors during the compute function execution of the block are stored in the state. When a block fails, only the blocks dependent on it are skipped, and the rest of the schema is executed.

This rather is the better way of keeping track of the errors and the status when compared to st.empty() or session_state. I didn't want this to rely too much on streamlit's workflow. For the st.empty() the update did not accur as the placeholder object is bounced around from one function to the other.