Return a new HighLevelGraph with only the given layers and their dependencies. Internally, layers are not modified. This is a variant of :meth:`HighLevelGraph.cull` which is much faster and does not risk creating a collision between two layers with the same name and
(self, layers: Iterable[str])
| 792 | return HighLevelGraph(ret_layers, ret_dependencies) |
| 793 | |
| 794 | def cull_layers(self, layers: Iterable[str]) -> HighLevelGraph: |
| 795 | """Return a new HighLevelGraph with only the given layers and their |
| 796 | dependencies. Internally, layers are not modified. |
| 797 | |
| 798 | This is a variant of :meth:`HighLevelGraph.cull` which is much faster and does |
| 799 | not risk creating a collision between two layers with the same name and |
| 800 | different content when two culled graphs are merged later on. |
| 801 | |
| 802 | Returns |
| 803 | ------- |
| 804 | hlg: HighLevelGraph |
| 805 | Culled high level graph |
| 806 | """ |
| 807 | to_visit = set(layers) |
| 808 | ret_layers = {} |
| 809 | ret_dependencies = {} |
| 810 | while to_visit: |
| 811 | k = to_visit.pop() |
| 812 | ret_layers[k] = self.layers[k] |
| 813 | ret_dependencies[k] = self.dependencies[k] |
| 814 | to_visit |= ret_dependencies[k] - ret_dependencies.keys() |
| 815 | |
| 816 | return HighLevelGraph(ret_layers, ret_dependencies) |
| 817 | |
| 818 | def validate(self) -> None: |
| 819 | # Check dependencies |