class_docstr: An inference block combining multiple perception blocks into one prediction module.
          Conditions on using the InferenceBlock object:
              1. All keys of the perception_blocks dictionary have to be unique
              2. All out_keys used when creating the blocks have to be unique
              3. All block keys in the perception_blocks dict have to sub-strings of all their corresponding out_keys
              4. The given in_keys should be a subset of the inputs of the computational graph
              5. The given out_keys should be a subset of the outputs of the computational graph
  
  :param in_keys: Keys identifying the input tensors.
  :param out_keys: Keys identifying the output tensors.
  :param in_shapes: List of input shapes.
  :param perception_blocks: Dictionary of perception blocks.
class_docstr_tok: ["An","inference","block","combining","multiple","perception","blocks","into","one","prediction","module",".","Conditions","on","using","the","InferenceBlock","object",":","1",".","All","keys","of","the","perception_blocks","dictionary","have","to","be","unique","2",".","All","out_keys","used","when","creating","the","blocks","have","to","be","unique","3",".","All","block","keys","in","the","perception_blocks","dict","have","to","sub-strings","of","all","their","corresponding","out_keys","4",".","The","given","in_keys","should","be","a","subset","of","the","inputs","of","the","computational","graph","5",".","The","given","out_keys","should","be","a","subset","of","the","outputs","of","the","computational","graph",":","param","in_keys",":","Keys","identifying","the","input","tensors",".",":","param","out_keys",":","Keys","identifying","the","output","tensors",".",":","param","in_shapes",":","List","of","input","shapes",".",":","param","perception_blocks",":","Dictionary","of","perception","blocks","."]
docstr: Test the defined conditions
  
  :param perception_blocks: Dictionary of perception blocks.
  :param in_keys: The in_keys of the perception block
  :param out_keys: The out_keys of the perception block
docstr_tok: ["Test","the","defined","conditions",":","param","perception_blocks",":","Dictionary","of","perception","blocks",".",":","param","in_keys",":","The","in_keys","of","the","perception","block",":","param","out_keys",":","The","out_keys","of","the","perception","block"]
code: def _test_condition(
      cls,
      perception_blocks: Dict[str, PerceptionBlock],
      in_keys: List[str],
      out_keys: List[str],
  ):
      """Test the defined conditions
  
      :param perception_blocks: Dictionary of perception blocks.
      :param in_keys: The in_keys of the perception block
      :param out_keys: The out_keys of the perception block
      """
      # 1. All keys of the perception_blocks dictionary have to be unique
      assert len(set(perception_blocks.keys())) == len(
          list(perception_blocks.keys())
      )
  
      # 2. All out_keys used when creating the blocks have to be unique
      all_out_keys = sum(
          [block.out_keys for block in perception_blocks.values()], []
      )
      assert len(set(all_out_keys)) == len(
          list(all_out_keys)
      ), f"{all_out_keys}, {len(set(all_out_keys))} vs {len(list(all_out_keys))}"
  
      # 3. All block keys in the perception_blocks dict have to sub-strings of all their corresponding out_keys
      for block_key, block in perception_blocks.items():
          for out_key in block.out_keys:
              assert block_key in out_key, (
                  f"out_key ({out_key}) is not a superset of the block_key "
                  f"({block_key}) it belongs to."
              )
  
      # Test the structure of the graph
      all_in_keys = sum(
          [block.in_keys for block in perception_blocks.values()], []
      )
      all_out_keys = sum(
          [block.out_keys for block in perception_blocks.values()], []
      )
  
      # 4. The inputs to the computational graph should be a subset of the given in_keys
      graph_in_keys = set(all_in_keys) - set(all_out_keys)
      assert all(
          [in_key in in_keys for in_key in graph_in_keys]
      ), f"in_keys of the network: {set(all_in_keys) - set(all_out_keys)}, vs specified in_keys: {set(in_keys)}"
  
      # 5. The given out_keys should be a subset of the outputs of blocks in the graph
      assert all(
          [out_key in all_out_keys for out_key in out_keys]
      ), f"Out_keys of the network: {set(all_out_keys)}, vs specified out_keys: {set(out_keys)}"
  
imports: import os
  import pickle
  from typing import Union, List, Dict, Optional, Sequence, Tuple
  import networkx
  import torch
  from matplotlib import pyplot
  from torch import nn
  from maze.core.annotations import override
  from maze.perception.blocks.base import PerceptionBlock
label_desc: Use image node_id 2 for calling the InferenceBlock obj's underlying member method code with example usage: obj._test_condition(cls, perception_blocks, in_keys, out_keys) without return types