Optimization using Python3 script crashes Rhino

I have a python3 script (that performs a simulation using the external software ngspice), that is used in a Galapagos optimization. Rhino crashes after a couple of minutes, without a crash report.
I have tried the opossum solver, same behavior here. I have a try - except block for the main function that is called but it is not catching anything.

From what I can tell:

  • There is no memory issue
  • There is no infinite loop

Here’s my system info:

Rhino 8 SR28 2026-2-10 (Rhino 8, 8.28.26041.11001, Git hash:master @ b7874a05a6982d0419fcc4f6009b510b48a09cb3)
License type: Commercial, build 2026-02-10
License details: Cloud Zoo

Windows 11 (10.0.26200 SR0.0) or greater (Physical RAM: 64GB)
.NET 8.0.14

Computer platform: DESKTOP

Standard graphics configuration.
Primary display and OpenGL: NVIDIA GeForce RTX 4090 (NVidia) Memory: 24GB, Driver date: 12-30-2025 (M-D-Y). OpenGL Ver: 4.6.0 NVIDIA 591.74
> Accelerated graphics device with 4 adapter port(s)
- Secondary monitor attached to adapter port #0
- Windows Main Display attached to adapter port #1

Secondary graphics devices.
Intel(R) UHD Graphics 770 (Intel) Memory: 2GB, Driver date: 12-1-2025 (M-D-Y).
> Integrated graphics device with 4 adapter port(s)
- There are no monitors attached to this device!

OpenGL Settings
Safe mode: Off
Use accelerated hardware modes: On
GPU Tessellation is: On
Redraw scene when viewports are exposed: On
Graphics level being used: OpenGL 4.6 (primary GPU’s maximum)

Anti-alias mode: 4x
Mip Map Filtering: Linear
Anisotropic Filtering Mode: High

Vendor Name: NVIDIA Corporation
Render version: 4.6
Shading Language: 4.60 NVIDIA
Driver Date: 12-30-2025
Driver Version: 32.0.15.9174
Maximum Texture size: 32768 x 32768
Z-Buffer depth: 24 bits
Maximum Viewport size: 32768 x 32768
Total Video Memory: 24564 MB

Rhino plugins that do not ship with Rhino

Rhino plugins that ship with Rhino
C:\Program Files\Rhino 8\Plug-ins\Commands.rhp	“Commands”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\rdk.rhp	“Renderer Development Kit”	
C:\Program Files\Rhino 8\Plug-ins\RhinoRenderCycles.rhp	“Rhino Render”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\rdk_etoui.rhp	“RDK_EtoUI”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\NamedSnapshots.rhp	“Snapshots”	
C:\Program Files\Rhino 8\Plug-ins\MeshCommands.rhp	“MeshCommands”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\IronPython\RhinoDLR_Python.rhp	“IronPython”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\RhinoCycles.rhp	“RhinoCycles”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\Grasshopper\GrasshopperPlugin.rhp	“Grasshopper”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\Toolbars\Toolbars.rhp	“Toolbars”	8.28.26041.11001
C:\Program Files\Rhino 8\Plug-ins\3dxrhino.rhp	“3Dconnexion 3D Mouse”	
C:\Program Files\Rhino 8\Plug-ins\Displacement.rhp	“Displacement”	
C:\Program Files\Rhino 8\Plug-ins\Calc.rhp	“Calc”	
C:\Program Files\Rhino 8\Plug-ins\SectionTools.rhp	“SectionTools”

Here’s also my python script:

import numpy as np

import PySpice
import PySpice.Logging.Logging as Logging
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *
from PySpice.Spice.NgSpice.Shared import NgSpiceShared

from Grasshopper import DataTree



def calculate_power (Voltage, plus_pole, minus_pole, netlist):

    #create logger
    logger = Logging.setup_logging()


    #initialize circuit
    circuit = Circuit("Optimization Circuit")

    circuit.V('input', plus_pole, minus_pole, Voltage@u_V)

    #Iterate through all Resistors in the netlist

    

    for i in range(netlist.BranchCount):
        item = netlist.Branch(i)
        #get values of individual resistances
        name = i
        #print(name)
        node_a = item[4]
        #print(node_a)
        node_b = item[5]
        #print(node_b)
        resistance = item[6]
        #print(resistance)

        #add Resistors
        resistor = circuit.R(name, node_a, node_b, resistance)
        
        #Create a current probe for all Resistors
        resistor.plus.add_current_probe(circuit)

    #Create Simulation Object    
    simulator = circuit.simulator(temperature=25, nominal_temperature=25)

    ngspice = NgSpiceShared.new_instance()

    #Create Analysis 
    analysis = simulator.operating_point()

    ngspice.destroy()    

    power_list = []


    for i in range(netlist.BranchCount):
        item = netlist.Branch(i)
        name = i
        node_a = item[4]
        node_b = item[5]

        #Check if node is part of the Analysis (ground node is not)
        if str(node_a) in analysis.nodes:
            # .item(0) converts np array to scalar
            v_a = analysis.nodes[str(node_a)].item(0)
        else: v_a = 0.0
        if str(node_b) in analysis.nodes:
            v_b = analysis.nodes[str(node_b)].item(0)
        else: v_b = 0.0

        voltage = v_a - v_b

        current = analysis.branches["vr{}_plus".format(name)].item(0)

        power = abs(current * voltage)
        
        power_list.append(power)
    return power_list
    

    


try:
    a = calculate_power(voltage, plus_pole, minus_pole, netlist)
except:
    print("error")

Is it possible that Grasshopper is not “waiting” for the python script to finish?
I also tried to not use Galapagos but iterate all possible solutions which made Rhino crash as well.

What I noticed when using the annealing solver is, that it will always crash at the exact same spot:

on the 4th iteration? when it reached 6,42 x10-16.

Any ideas are welcome!

reduce computational complexity

ask chatgpt and itll get it rite

Thank you for your suggestion!
I removed a couple of flaws in my code but it still crashes at the same point as before.

Have you got an error report or Traceback? Is that PySpice logger configured to send its logs somewhere you can get them, or can you connect the Out param to a text box and copy and paste from that?