Errors running python component with Hops & rhinoinside

The definition in the following picture used to work (although very slowly) until I added a bunch of necessary data to it and it ran out of memory.

This is a very complex & long definition. I need to find a way around it, I’m trying to run the definition directly on a Hops module using rhinoinside, but it doesn’t seem to work.
When I isolate one of the definitions in that code, and I try to run it:

import rhinoinside
import ghhops_server as hs

rhinoinside.load()
# register hops app as middleware\
import System
import Rhino
from Rhino import Geometry as rg
import math

hops = hs.Hops(app=rhinoinside)


@hops.component(
    "/test",
    name="Test",
    description="Test Hops functionality",
    inputs=[
        hs.HopsPoint("Corner", "corner_pts", "Corner Points"),
        hs.HopsCurve("Edges", "edges", "Front Facades"),
    ],
    outputs=[
        hs.HopsCurve("Test 1", "test1", "bleh"),
        hs.HopsInteger("Test 2", "test2", "bleh2"),
    ],
)

def testdef(corner_pts, edges):
    ''' Find Secondary Edges '''

    def secondary_edges(edges, corner_pts_list):
        all_add_crvs = []
        all_add_angle = []
        edges = [edges]
        for crv in edges:
            print(crv)
            end_t = rg.Curve.DivideByCount(crv, 1, True)
            print(end_t)
            end_pt = [rg.Curve.PointAt(crv, x) for x in end_t]
            print(end_pt)
            crv_line = rg.Line(end_pt[0], end_pt[1])

            ...

    sec_def = secondary_edges(edges, corner_pts)

    test = sec_def[0]
    test2 = sec_def[1]

    return test, test2

What I get out of the end_t = rg.Curve.DivideByCount(crv, 1, True) is System.Double[], which is empty. It obviously should have 2 values, and that creates the following error:
[DEBUG] Exception occured in handler: list index out of range

In the meantime, it’s creating this Error:

{'InnerTree': {'{1}': [{'data': '{"version":10000,"archive3dm":70,"opennurbs":-1903130291,"data":"+n8CAIkAAAAAAAAA+/8CABQAAAAAAAAA5tTXTkfp0xG/5QAQgwEi8E6cu9v8/wIAUQAAAAAAAAAQAgAAACKmF2nbn0vA8ygQoNJOk8AAAAAAAAAAAEhML9K2PznAINShs7iJk8AAAAAAAAAAAAIAAAAAAAAAAAA+QFRV3kybtU9AAwAAAN/JKtL/fwKAAAAAAAAAAAA="}',
                        'type': 'Rhino.Geometry.PolylineCurve'}]},
 'ParamName': 'Edges'}
[INFO] Solving using legacy API: <HopsComponent /testhops2 [Edges -> Test -> Test 1,Test 2] >
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 50683)
Traceback (most recent call last):

(...)

File "C:\Users\ ... \venv\lib\site-packages\ghhops_server\params.py", line 210, in from_input
    for param_value_item in input_data["InnerTree"]["{0}"]:
KeyError: '{0}'
----------------------------------------

I really don’t understand where the problem is, and this might affect so many areas in the code that I don’t even know where to start to make it fully work. Any ideas? Other ways of running it?
Here’s the git for the full test code + gh file with test inputs:

Thank you,

Lev

@l.zhitnik You can use Rhino.Compute to run Rhino and Grasshopper on a server and send request to solve definitions to it.

But honestly I doubt it would help. OutOfMemoryException is fairly serious. We have lots and lots of memory on modern machines so more often than not when you run our of memory, there is a memory leak somewhere.

What is the definition doing that requires all the memory?

Hey Ehsan,

The definition tests more than 10,000 geometries and manipulates them, to extract data from them.
Thing is, this isn’t the first time I see Grasshopper having a major memory leak, while similar operations in another IDE take a fraction of the memory and time to solve.

Can Rhino.Compute run an existing Python module I already wrote in gh with a live feed of inputs from the gh document? Do you have any documentation for it?

All I can find is the well known Hops tutorial that uses rhino3dm, and it cuts when it gets to the rhinoinside part (which actually has the modules from rhinocommon that I need)

I just updated the question with the results I’ve been getting with rhinoinside and Hops.
I will test the Rhino.Compute documentation in the meantime to see if I can use that instead.

Thanks again,

Lev

Are you using any Clusters in the grasshopper definition?

See this conversation. I pushed a fix for this for Rhino 8.8

We have a Rhino 7 license, and that definition in particular has a few small clusters but I do work with clusters often. I need to find a way to work around it at the moment with Rhino 7…

In the meantime, it’s creating this Error:

{'InnerTree': {'{1}': [{'data': '{"version":10000,"archive3dm":70,"opennurbs":-1903130291,"data":"+n8CAIkAAAAAAAAA+/8CABQAAAAAAAAA5tTXTkfp0xG/5QAQgwEi8E6cu9v8/wIAUQAAAAAAAAAQAgAAACKmF2nbn0vA8ygQoNJOk8AAAAAAAAAAAEhML9K2PznAINShs7iJk8AAAAAAAAAAAAIAAAAAAAAAAAA+QFRV3kybtU9AAwAAAN/JKtL/fwKAAAAAAAAAAAA="}',
                        'type': 'Rhino.Geometry.PolylineCurve'}]},
 'ParamName': 'Edges'}
[INFO] Solving using legacy API: <HopsComponent /testhops2 [Edges -> Test -> Test 1,Test 2] >
----------------------------------------
Exception occurred during processing of request from ('127.0.0.1', 50683)
Traceback (most recent call last):

(...)

File "C:\Users\ ... \venv\lib\site-packages\ghhops_server\params.py", line 210, in from_input
    for param_value_item in input_data["InnerTree"]["{0}"]:
KeyError: '{0}'
----------------------------------------


I really don’t understand where the problem is.

Sorry for posting multiples comments. I think I understand that I can’t use hops while working with multiple branches? The moment the data is flattened - small subsets of the code work. When I bring back the data in a branched form - it stops working and displays the error messages above.