r"""Loads a computing graph as a Network object. Args: model_path: file path of mge model. outspec: only load the subgraph with outspec as its endpoints.
(cls, model_path: str, outspec: List[str] = None)
| 62 | |
| 63 | @classmethod |
| 64 | def load(cls, model_path: str, outspec: List[str] = None): |
| 65 | r"""Loads a computing graph as a Network object. |
| 66 | |
| 67 | Args: |
| 68 | model_path: file path of mge model. |
| 69 | outspec: only load the subgraph with outspec as its endpoints. |
| 70 | """ |
| 71 | self = cls() |
| 72 | ret = G.load_graph(model_path) |
| 73 | outputs, self._metadata = ret.output_vars_list, ret.metadata |
| 74 | if outspec is not None: |
| 75 | output_spec = outspec.copy() |
| 76 | all_vars = get_dep_vars(outputs) + outputs |
| 77 | new_outputs = {} |
| 78 | for i in all_vars: |
| 79 | if i.name in output_spec: |
| 80 | new_outputs[i.name] = i |
| 81 | output_spec.remove(i.name) |
| 82 | assert len(output_spec) == 0, "Can not find {} in this model".format( |
| 83 | output_spec |
| 84 | ) |
| 85 | outputs = [new_outputs[i] for i in outspec] |
| 86 | self._orig_outputs = outputs |
| 87 | for x in self._orig_outputs: |
| 88 | self.output_vars.append(self._get_var(x)) |
| 89 | self.add_dep_oprs() |
| 90 | for x in self._orig_inputs: |
| 91 | self.input_vars.append(self._get_var(x)) |
| 92 | |
| 93 | self.graph = self._orig_outputs[0].graph |
| 94 | return self |
| 95 | |
| 96 | def _compile(self): |
| 97 | self.all_oprs_map = {} |
no test coverage detected