Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applies metagraph fix and assertions #2235

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
Loading