Python kernel crashes when solving Pyomo model created with OMLT using Cyipopt

I am trying to solve an optimization problem that has a neural network as a constraint. I am creating that constraint within Pyomo using the package OMLT. I am using Cyipopt as the optimizer. I am doing a comparative study using the Pynumero greybox platform which is only compatible with Cyipopt, thus, I must use Cyipopt to keep the optimizer consistent. It starts to run as expected but at some point the kernel inadvertently crashes. Does anyone know any work around this issue?

I think that there must be some incompatibility issue with the packages. I installed most of them from conda, some are only available from pip. I have try different versions and changing the source, but it does not seem to resolve it. The following is a toy example where this problems occurs.

import torch
import numpy as np

import tempfile

from omlt.io import write_onnx_model_with_bounds,load_onnx_neural_network
from omlt import OmltBlock, OffsetScaling
from omlt.neuralnet import FullSpaceNNFormulation
import onnx

import pyomo.environ as pyo

import matplotlib.pyplot as plt

class neuralnetwork(torch.nn.Module):
    def __init__(self):
        super().__init__()
    
        self.activ = torch.nn.Sigmoid()
        
        self.Dense1 = torch.nn.Linear(2,5)
        
        self.Dense2 = torch.nn.Linear(5,1)
        
    def forward(self, x):
        
        x = self.Dense1(x)
        
        x = self.activ(x)
        
        x= self.Dense2(x)
        
        return x
    
def PyomoModel(NN):
    
    x = torch.randn(1,2)
    
    with tempfile.NamedTemporaryFile(suffix='.onnx', delete=False) as f:
        torch.onnx.export(
            NN,
            x,
            f,
            input_names=['input'],
            output_names=['output'],
            dynamic_axes={
                'input': {0: 'batch_size'},
                'output': {0: 'batch_size'}
            }
        )
        
    input_bounds = [(-1,1) for _ in range(2)]
    
    scaler = OffsetScaling(
        offset_inputs=np.zeros(2),
        factor_inputs=np.ones(2),
        offset_outputs=np.zeros(1),
        factor_outputs=np.ones(1)
    )
    
    write_onnx_model_with_bounds(f.name, None, input_bounds)
    
    onnx_model = onnx.load(f.name)
    print(f"Wrote PyTorch model to {f.name}")
    
    network_definition = load_onnx_neural_network(onnx_model, scaling_object=scaler)
    
    formulation = FullSpaceNNFormulation(network_definition)
    
    mdl = pyo.ConcreteModel()
    
    mdl.nn = OmltBlock()
    
    mdl.nn.build_formulation(formulation)
    
    mdl.cons1 = pyo.Constraint(expr=-1<=mdl.nn.inputs[1])
    
    mdl.cons2 =pyo.Constraint(expr=mdl.nn.inputs[1]<=1)
    
    mdl.obj = pyo.Objective(expr=mdl.nn.outputs[0]**2)
    
    return mdl

def main():
    
    NN = neuralnetwork()
    
    mdl = PyomoModel(NN)
    
    x_1 = np.linspace(-1,1,10)
    x_2 = []
    y = []
    
    solver = pyo.SolverFactory('cyipopt')
    
    for i in range(10):
        
        mdl.nn.inputs[0].fix(x_1[i])
        
        results = solver.solve(mdl, tee=True)
        
        x_2.append(mdl.nn.inputs[1].value)
        y.append(mdl.nn.outputs[0].value)
        
        plt.plot(x_1[0:i+1], x_2, 'o')
        plt.plot(x_1[0:i+1], y, 'o')
        
        plt.show()
        
    
if __name__ == "__main__":
    main()

Edit

I have tried using OMLT 1.1, 1.2, 1.0 installed from pip, pynumero_libraries 1.3, 1.2 installed with conda-forge,
and pytorch 2.0.1, 2.4.0, 2.3.0 installed from pip and conda with and without cuda.
Additionally, I recently noticed that when I run it from the terminal, it shows the following error which VScode does not show.

FileNotFoundError: [Errno 2] No such file or directory: 'c:\Users\~\AppData\Local\Programs\Microsoft VS Code\Untitled-1'
OMP: Error #15: Initializing libomp.dll, but found libiomp5md.dll already initialized.
OMP: Hint: This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://openmp.llvm.org/

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật