code: def get_nn_domain_from_constraints(nn_type, constraint_dict):
      """nn_type is the type of the network.
      See CNNConstraintChecker, MLPConstraintChecker, NNConstraintChecker constructors
      for args and kwargs.
      """
      constraint_dict = copy(constraint_dict)
      # Specify the mandatory and optional key values
      mandatory_keys = ["max_num_layers", "max_mass"]
      optional_key_vals = [
          ("min_num_layers", 5),
          ("min_mass", 0),
          ("max_out_degree", np.inf),
          ("max_in_degree", np.inf),
          ("max_num_edges", np.inf),
          ("max_num_units_per_layer", 10001),
          ("min_num_units_per_layer", 5),
      ]
      if nn_type.startswith("cnn"):
          optional_key_vals += [("max_num_2strides", np.inf)]
      # Check if the mandatory keys exist in constraint_dict
      for mkey in mandatory_keys:
          if mkey not in constraint_dict.keys():
              raise ValueError(
                  "Must specify keys %s in constraint_dict."
                  % (", ".join(mandatory_keys))
              )
      # If an optional key does not exist, then add it
      for okey, oval in optional_key_vals:
          if okey not in constraint_dict.keys():
              constraint_dict[okey] = oval
      # Specify the constructor
      if nn_type.startswith("cnn"):
          cc_constructor = CNNConstraintChecker
      elif nn_type.startswith("mlp"):
          cc_constructor = MLPConstraintChecker
      else:
          raise ValueError("Unknown nn_type: %s." % (nn_type))
      # Now create constraint checker object
      cc_attributes = mandatory_keys + [
          okv[0] for okv in optional_key_vals
      ]
      constraint_dict_to_pass = {
          key: constraint_dict[key] for key in cc_attributes
      }
      constraint_checker = cc_constructor(**constraint_dict_to_pass)
      # Create Domain and return
      return NNDomain(nn_type, constraint_checker)
  
imports: import numpy
  from copy import copy
  from ..exd.domains import Domain
label_desc: Use image node_id 2 for calling a global function with example usage: get_nn_domain_from_constraints(nn_type, constraint_dict) and returns: NNDomain