class_docstr: Test the basic error handling / validation in pymil.
class_docstr_tok: ["Test","the","basic","error","handling","\/","validation","in","pymil","."]
docstr: Test we can get a dict of dialect namespaces in the program.
docstr_tok: ["Test","we","can","get","a","dict","of","dialect","namespaces","in","the","program","."]
code: def test_get_dialect_namespaces():
      """
      Test we can get a dict of dialect namespaces in the program.
      """
  
      # The pymil program is mixed of torch / complex dialect opset
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(2, 2, 3, 4), dtype=types.fp32)
          ]
      )
      def prog(x):
          real_data = mb.torch_upsample_nearest_neighbor(
              x=x, output_height=10, output_width=5, name="op_1"
          )
          imag_data = mb.add(x=real_data, y=8.9, name="op_2")
          return mb.complex(
              real_data=real_data, imag_data=imag_data, name="op_3"
          )
  
      dialect_namespaces = prog._get_dialect_namespaces()
      assert len(dialect_namespaces["torch"]) == 1
      assert dialect_namespaces["torch"][0].name == "op_1"
      assert len(dialect_namespaces["complex"]) == 1
      assert dialect_namespaces["complex"][0].name == "op_3"
  
      # The pymil program with only core ops returns an empty dict
      @mb.program(
          input_specs=[
              mb.TensorSpec(shape=(2, 2, 3, 4), dtype=types.fp32)
          ]
      )
      def prog(x):
          return mb.add(x=x, y=8.9)
  
      assert len(prog._get_dialect_namespaces()) == 0
  
imports: import numpy
  import pytest
  import coremltools
  from coremltools import _logger
  from coremltools.converters.mil.mil import Builder
  from coremltools.converters.mil.mil import Function, Program, types
  from coremltools.converters.mil.mil.passes.tests.test_passes import CONSTEXPR_FUNCS
label_desc: Use image node_id 2 for calling the TestMILBasic obj's underlying member method code with example usage: obj.test_get_dialect_namespaces() and returns: mb, mb