Exemple #1
0
    def __init__(self):

        # Set up an invert operation
        @OperationPlugin
        @output_names('inverted_data')
        def invert(data: np.ndarray = None) -> np.ndarray:
            if issubclass(data.dtype.type, np.integer):
                max = np.iinfo(data.dtype).max
            else:
                max = np.finfo(data.dtype).max
            return max - data

        # Set up our workflow
        workflow = Workflow()
        workflow.add_operation(invert)
        workflow_editor = WorkflowEditor(workflow)

        # Set up a GUI layout
        center_widget = QLabel("test")
        sample_stage_layout = GUILayout(center_widget)

        # Set up stages
        stages = {
            "Sample Stage": GUILayout(center_widget, right=workflow_editor)
        }
        self.stages = stages
        super(SamplePlugin, self).__init__()
Exemple #2
0
def test_workflow():
    from xicam.core.execution.workflow import Workflow
    from xicam.core.execution.daskexecutor import DaskExecutor
    from xicam.plugins.operationplugin import output_names

    executor = DaskExecutor()

    @operation
    @output_names("square")
    def square(a=3) -> int:
        return a**2

    @operation
    @output_names("sum")
    def my_sum(a, b=3) -> int:
        return a + b

    wf = Workflow()

    square = square()
    my_sum = my_sum()

    wf.add_operation(square)
    wf.add_operation(my_sum)
    wf.add_link(square, my_sum, "square", "a")

    assert wf.execute_synchronous(executor=executor) == [{"sum": 12}]
Exemple #3
0
def custom_parameter_workflow(custom_parameter_op):
    from xicam.core.execution.workflow import Workflow

    wf = Workflow()

    custom_parameter_op = custom_parameter_op()

    wf.add_operation(custom_parameter_op)
    return wf
    def test_execute_operation_no_default_no_value(self, sum_op):
        # not sure how to test this....
        def handle_exception(exception):
            with pytest.raises(TypeError):
                raise exception

        workflow = Workflow()
        workflow.add_operation(sum_op)
        results = workflow.execute(except_slot=handle_exception).result()
        print(results)
Exemple #5
0
    def test_execute_operation_default_input_value(self):
        @operation
        @output_names("doubled")
        def double_op(x=10):
            return x * 2

        workflow = Workflow()
        workflow.add_operation(double_op)
        results = workflow.execute().result()
        assert results == ({"doubled": 20}, )
 def test_default(self, op, old):
     w = Workflow(operations=[op])
     result = w.execute_synchronous(executor=executor)
     corrected_images = result[0]['corrected_images']
     gains = get_default(op, 'gains')
     assert np.array_equal(corrected_images,
                           op.filled_values['images'] * gains[0])
     if TEST_CSX_TOOLS:
         w.clear_operations()
         w.add_operation(old)
         result = w.execute_synchronous(executor=executor)
         assert np.array_equal(result[0]['corrected_images'],
                               corrected_images)
Exemple #7
0
def simple_workflow_with_intents(plot_op, abs_plot_op, blur_image_op,
                                 image_op):
    wf = Workflow()

    wf.add_operation(image_op)
    wf.add_operation(blur_image_op)
    wf.add_link(image_op, blur_image_op, "output_array", "arr")

    wf.add_operation(plot_op)
    wf.add_operation(abs_plot_op)
    wf.add_link(plot_op, abs_plot_op, "output1", "x_arr")
    wf.add_link(plot_op, abs_plot_op, "output2", "y_arr")

    return wf
Exemple #8
0
def simple_workflow(square_op, sum_op):
    from xicam.core.execution.workflow import Workflow

    wf = Workflow()

    square = square_op
    square2 = square_op.__class__()
    square2.filled_values["n"] = 2

    wf.add_operation(square)
    wf.add_operation(square2)
    wf.add_operation(sum_op)
    wf.add_link(square, sum_op, "square", "n1")
    wf.add_link(square2, sum_op, "square", "n2")

    return wf
Exemple #9
0
def test_multiple_instances(square_op, sum_op):
    from xicam.core.execution.workflow import Workflow
    from xicam.core.execution.daskexecutor import DaskExecutor

    executor = DaskExecutor()

    wf = Workflow()

    square = square_op()
    square2 = square_op()
    square2.filled_values["a"] = 2
    my_sum = sum_op()

    wf.add_operation(square)
    wf.add_operation(square2)
    wf.add_operation(my_sum)
    wf.add_link(square, my_sum, "square", "a")  # 3**3
    wf.add_link(square2, my_sum, "square", "b") # 2**2
    assert wf.execute_synchronous(executor=executor) == [{"sum": 13}]
def test_multiple_instances(square_op, sum_op):
    from xicam.core.execution.workflow import Workflow
    from xicam.core.execution.daskexecutor import DaskExecutor

    executor = DaskExecutor()

    wf = Workflow()

    square = square_op()
    square2 = square_op()
    square2.filled_values['a'] = 2
    my_sum = sum_op()

    wf.add_operation(square)
    wf.add_operation(square2)
    wf.add_operation(my_sum)
    wf.add_link(square, my_sum, 'square', 'a')
    wf.add_link(square2, my_sum, 'square', 'b')

    assert wf.execute_synchronous(executor=executor) == [{'sum': 13}]
 def test_execute_operation_no_default(self, sum_op):
     workflow = Workflow()
     workflow.add_operation(sum_op)
     results = workflow.execute(n1=10, n2=5).result()
     assert results == ({"sum": 15}, )