SMILE cannot create a network, error -42

The engine.
Post Reply
BayesFusionUser123
Posts: 23
Joined: Tue Jun 10, 2025 3:51 pm

SMILE cannot create a network, error -42

Post by BayesFusionUser123 »

I got an error when creating a network using the code below:

Code: Select all

from functools import partial
import pysmile
import pysmile_license


def create_cpt_node(net, id, name, outcomes, x_pos, y_pos):
    
    handle = net.add_node(pysmile.NodeType.CPT, id)
    
    net.set_node_name(handle, name)
    net.set_node_position(handle, x_pos, y_pos, 85, 55)
    
    initial_outcome_count = net.get_outcome_count(handle)
    
    for i in range(0, initial_outcome_count):
        net.set_outcome_id(handle, i, outcomes[i])
    
    for i in range(initial_outcome_count, len(outcomes)):
        net.add_outcome(handle, outcomes[i])
        
    return handle


def construct_SMILE_network_with_n_parents(n_parents):
    """
    Construct SMILE predefined network and save it to output folder
    
    Build a causal DAG:
    
    P_1 -> T -> O
    P_2 -> T -> O
    ...
    P_n -> T -> O
    
    """
    var_unique_val_dict = {}
    var_unique_val_dict["T"] = ["T___1", "T___0"]
    var_unique_val_dict["O"] = ["O___1", "O___0"]
    for i in range(n_parents):
        var_unique_val_dict[f"P_{i + 1}"] = [f"P_{i + 1}___1", f"P_{i + 1}___0"]
    #endfor
    
    
    predefined_hybrid_net = pysmile.Network()

    # (1) add all nodes properly
    x = 10
    var_to_val_list_dict = {}

    for var_name in var_unique_val_dict.keys():
        #print(var_name)
        var_val_list = var_unique_val_dict[var_name]
        var_to_val_list_dict[var_name] = var_val_list
        create_cpt_node(predefined_hybrid_net, var_name, var_name, var_val_list, 10, x)
        x += 10
    #endfor

    print("SMILE var_to_val_list_dict:")
    for var_n, var_val_list in var_to_val_list_dict.items():
        print(f"{var_n}: {var_val_list}")
    #endfor
    
    
    # (2)
    for i in range(n_parents):
        parent = f"P_{i+1}"
        predefined_hybrid_net.add_arc(parent, "T")
        print(f"method-[construct_SMILE_network_with_n_parents] add_arc: {parent} -> T")
    #endfor
    predefined_hybrid_net.add_arc('T', "O")
    
    return predefined_hybrid_net


SMILE_net = construct_SMILE_network_with_n_parents(37)


The error message is like below:

Code: Select all

Traceback (most recent call last):
  File "20260430_SMILE_network_creation_error_-42.py", line 75, in <module>
    SMILE_net = construct_SMILE_network_with_n_parents(37)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "20260430_SMILE_network_creation_error_-42.py", line 67, in construct_SMILE_network_with_n_parents
    predefined_hybrid_net.add_arc(parent, "T")
pysmile.SMILEException: SMILE Error -42 in function Network.AddArc
Could you please tell me the reason of this error, how to correct it and what does error -42 mean?
Thanks.
shooltz[BayesFusion]
Site Admin
Posts: 1494
Joined: Mon Nov 26, 2007 5:51 pm

Re: SMILE cannot create a network, error -42

Post by shooltz[BayesFusion] »

Error code -42 indicates an out-of-memory exception caught by SMILE. In your case, it's most likely at add_arc call used to connect P_{i+1} and T.

In SMILE, the single CPT can have 2^31 elements - with all binary nodes this would be a node with 30 parents.
BayesFusionUser123
Posts: 23
Joined: Tue Jun 10, 2025 3:51 pm

Re: SMILE cannot create a network, error -42

Post by BayesFusionUser123 »

"In SMILE, the single CPT can have 2^31 elements - with all binary nodes this would be a node with 30 parents."
Is this a hard limit, OR is it possible to extend this limit somehow?
shooltz[BayesFusion]
Site Admin
Posts: 1494
Joined: Mon Nov 26, 2007 5:51 pm

Re: SMILE cannot create a network, error -42

Post by shooltz[BayesFusion] »

This is the hard limit for the CPT representation.

You can have more than 31 parents if you use NoisyMAX nodes instead of CPT nodes, and enabled NoisyMAX decomposition in network properties.

For more information, refer to SMILE Wrappers Manual chapter "Noisy-MAX decomposition", in the PDF version chapter number is 6.6.2.
Post Reply