Dessia-tech / dessia_common

GNU Lesser General Public License v2.1
1 stars 2 forks source link

Fix: add block index to workflowrun zip #679

Closed younesdessia closed 7 months ago

younesdessia commented 8 months ago
younesdessia commented 8 months ago

Hi, In the Workflow object, if we have export blocks, we must pass index_block to the export method

younesdessia commented 8 months ago

@GhislainJ

here is a simple example to reproduce this issue !

from dessia_common.core import DessiaObject

class ObjectTest(DessiaObject):

    def __init__(self, name: str = "", measure: float = 1.1):
        self.measure = measure
        DessiaObject.__init__(self, name=name)

class InstantiateObject(DessiaObject):

    def __init__(self, name: str = ""):
        DessiaObject.__init__(self, name=name)

    def compute(self, measure: float = 1):
        return ObjectTest(measure=measure)
from dessia_common.typings import MethodType
from dessia_common.workflow.blocks import InstantiateModel, ModelMethod, Export
from dessia_common.workflow.core import Pipe, Workflow
from dessia_common.export_test import InstantiateObject

block_0 = InstantiateModel(model_class=InstantiateObject, name="InstantateObject")
block_1 = ModelMethod(method_type=MethodType(InstantiateObject, 'compute'), name="compute")
txt_method = MethodType(class_=InstantiateObject, name="save_to_stream")
export_txt = Export(method_type=txt_method, text=True, filename="export_json", extension="json", name="Export JSON")

blocks = [block_0, block_1, export_txt]

pipe_1 = Pipe(block_0.outputs[0], block_1.inputs[0])
pipe_2 = Pipe(block_0.outputs[0], export_txt.inputs[0])

workflow = Workflow(blocks, [pipe_1, pipe_2], output=block_1.outputs[0], name="test")

input_values = {

}

workflow_export_run = workflow.run(input_values)
workflow_export_run.zip_settings() # error block index when evaluate txt_method export method (block_index!)