MCPcopy Create free account
hub / github.com/microsoft/JARVIS / __init__

Method __init__

taskbench/graph_sampler.py:9–29  ·  view source on GitHub ↗
(self, graph: nx.Graph = None, file_name = None)

Source from the content-addressed store, hash-verified

7random.seed(0)
8class GraphSampler:
9 def __init__(self, graph: nx.Graph = None, file_name = None):
10 if file_name:
11 with open(file_name, "r") as f:
12 data = json.load(f)
13
14 # Represent your graph in NetworkX
15 graph = nx.DiGraph()
16
17 # Add nodes to the graph
18 if "input-type" in data["nodes"][0]:
19 for node in data["nodes"]:
20 graph.add_node(node["id"], desc=node["desc"], input_type=node["input-type"], output_type=node["output-type"])
21 else:
22 for node in data["nodes"]:
23 graph.add_node(node["id"], desc=node["desc"], parameters=node["parameters"])
24
25 # Add edges to the graph
26 for link in data["links"]:
27 graph.add_edge(link["source"], link["target"], type=link["type"])
28
29 self.graph = graph
30
31 def sample_subgraph_by_weight(self, number_weights, method_weights):
32 method = random.choices(list(method_weights.keys()), weights=list(method_weights.values()))[0]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected