Skip to content

Commit

Permalink
Applies fix and assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheem-opentensor committed Aug 14, 2024
1 parent a28963d commit 8022866
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions bittensor/metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def state_dict(self):
"bonds": self.bonds,
"uids": self.uids,
"axons": self.axons,
"neurons": self.neurons,
}

def sync(
Expand Down Expand Up @@ -782,6 +783,7 @@ def save(self) -> "metagraph": # type: ignore
graph_filename = f"{save_directory}/block-{self.block.item()}.pt"
state_dict = self.state_dict()
state_dict["axons"] = self.axons
state_dict["neurons"] = self.neurons
torch.save(state_dict, graph_filename)
state_dict = torch.load(
graph_filename
Expand Down Expand Up @@ -1029,6 +1031,7 @@ def load_from_path(self, dir_path: str) -> "metagraph": # type: ignore
)
self.uids = torch.nn.Parameter(state_dict["uids"], requires_grad=False)
self.axons = state_dict["axons"]
self.neurons = state_dict["neurons"]
if "weights" in state_dict:
self.weights = torch.nn.Parameter(
state_dict["weights"], requires_grad=False
Expand Down Expand Up @@ -1173,6 +1176,7 @@ def load_from_path(self, dir_path: str) -> "metagraph": # type: ignore
self.last_update = state_dict["last_update"]
self.validator_permit = state_dict["validator_permit"]
self.axons = state_dict["axons"]
self.neurons = state_dict["neurons"]
if "weights" in state_dict:
self.weights = state_dict["weights"]
if "bonds" in state_dict:
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e_tests/subcommands/subnet/test_metagraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ def test_metagraph_command(local_chain, capsys):
captured = capsys.readouterr()

# Assert the neuron is registered and displayed
assert (
"Metagraph: net: local:1" and "N: 1/1" in captured.out
), "Neuron isn't displayed in metagraph"
assert "Metagraph: net: local:1" in captured.out
assert "N: 1/1" in captured.out, "Neuron isn't displayed in metagraph"

# Register Dave as neuron to the subnet
dave_keypair, dave_exec_command, dave_wallet = setup_wallet("//Dave")
Expand Down Expand Up @@ -117,6 +116,7 @@ def test_metagraph_command(local_chain, capsys):
captured = capsys.readouterr()

# Assert the neuron is registered and displayed
assert "Metagraph: net: local:1" and "N: 2/2" in captured.out
assert "Metagraph: net: local:1" in captured.out
assert "N: 2/2" in captured.out

logging.info("Passed test_metagraph_command")

0 comments on commit 8022866

Please sign in to comment.