Skip to content

Commit

Permalink
Merge pull request #5 from opentensor/update-readme-file
Browse files Browse the repository at this point in the history
Updates the readme file
  • Loading branch information
ibraheem-opentensor authored Dec 3, 2024
2 parents 941a492 + 946e863 commit 9f29af1
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,36 @@ def get_encrypted_commit(
uids: Union[NDArray[np.int64], "torch.LongTensor"],
weights: Union[NDArray[np.float32], "torch.FloatTensor"],
version_key: int,
subnet_reveal_period_epochs: int = 1,
block_time: int = 12,
tempo: int = 360
tempo: int,
current_block: int,
netuid: int,
subnet_reveal_period_epochs: int,
block_time: int = 12
) -> tuple[bytes, int]:
"""Returns encrypted commit and target round for `commit_crv3_weights` extrinsic.
Arguments:
uids: The uids to commit.
weights: The weights associated with the uids.
version_key: The version key to use for committing and revealing. Default is `bittensor.core.settings.version_as_int`.
subnet_reveal_period_epochs: Number of epochs after which the revive will be performed. Corresponds to hyperparameter 'commit_reveal_weights_interval' of the subnet. In epochs.
block_time: Amount if seconds in one block. In seconds.
tempo: Amount of blocks in one Epoch.
tempo: Number of blocks in one epoch.
current_block: The current block number in the network.
netuid: The network unique identifier (NetUID) for the subnet.
subnet_reveal_period_epochs: Number of epochs after which the reveal will be performed. Corresponds to the hyperparameter `commit_reveal_weights_interval` of the subnet. In epochs.
block_time: Amount of time in seconds for one block. Defaults to 12 seconds.
Returns:
commit (bites): hex value of encrypted and compressed uids and weights values for setting weights.
commit (bytes): Raw bytes of the encrypted, and compressed uids & weights values for setting weights.
target_round (int): Drand round number when weights have to be revealed. Based on Drand Quicknet network.
"""
"""
# function logic
return commit, target_round
```


To test the function run in terminal:
1. Spin up a local subtensor branch which includes CR3
2. Create a subnet with netuid 1 (or replace the netuid with the one you create)
```bash
mkdir test
cd test
Expand All @@ -54,10 +60,20 @@ then copy-past to ipython
import numpy as np
import bittensor_commit_reveal as crv3
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
import bittensor as bt

uids = [1, 3]
weights = [0.3, 0.7]
version_key = 843000
netuid = 1

subtensor = bt.Subtensor("local")

subnet_reveal_period_epochs = subtensor.get_subnet_reveal_period_epochs(
netuid=netuid
)
tempo = subtensor.get_subnet_hyperparameters(netuid).tempo
current_block = subtensor.get_current_block()

if isinstance(uids, list):
uids = np.array(uids, dtype=np.int64)
Expand All @@ -66,15 +82,15 @@ if isinstance(weights, list):

uids, weights = convert_weights_and_uids_for_emit(uids, weights)

print(crv3.get_encrypted_commit(uids, weights, version_key))
print(crv3.get_encrypted_commit(uids, weights, version_key, tempo, current_block, netuid, subnet_reveal_period_epochs))
```
expected result
```python
(b'\xb9\x96\xe4\xd1\xfd\xabm\x8cc\xeb\xe3W\r\xc7J\xb4\xea\xa9\xd5u}OG~\xae\xcc\x9a@\xdf\xee\x16\xa9\x0c\x8d7\xd6\xea_c\xc2<\xcb\xa6\xbe^K\x97|\x16\xc6|;\xb5Z\x97\xc9\xb4\x8em\xf1hv\x16\xcf\xea\x1e7\xbe-Z\xe7e\x1f$\n\xf8\x08\xcb\x18.\x94V\xa3\xd7\xcd\xc9\x04F::\t)Z\xc6\xbey \x00\x00\x00\x00\x00\x00\x00\xaaN\xe8\xe97\x8f\x99\xbb"\xdf\xad\xf6\\#%\xca:\xc2\xce\xf9\x96\x9d\x8f\x9d\xa2\xad\xfd\xc73j\x16\xda \x00\x00\x00\x00\x00\x00\x00\x84*\xb0\rw\xad\xdc\x02o\xf7i)\xbb^\x99e\xe2\\\xee\x02NR+-Q\xcd \xf7\x02\x83\xffV>\x00\x00\x00\x00\x00\x00\x00"\x00\x00\x00\x00\x00\x00\x00*\x13wXb\x93\xc5"F\x17F\x05\xcd\x15\xb0=\xe2d\xfco3\x16\xfd\xe9\xc6\xbc\xd1\xb3Y\x97\xf9\xb9!\x01\x0c\x00\x00\x00\x00\x00\x00\x00X\xa2\x8c\x18Wkq\xe5\xe6\x1c2\x86\x08\x00\x00\x00\x00\x00\x00\x00AES_GCM_', 13300875)
```

To test this in local subnet you need:
1. Spinup local node based on the subtensor branch `spiigot/add-pallet-drand` using command `./scripts/localnet.sh "False"`
1. Spinup local node based on the subtensor branch `spiigot/add-pallet-drand` using command `./scripts/localnet.sh False`
2. Create subnet
3. Change the next hyperparameters:
- `commit_reveal_weights_enabled` -> `True`
Expand Down Expand Up @@ -159,7 +175,7 @@ import bittensor as bt

sub = bt.Subtensor(network="local")

netuid = 1 # your created subnets netuid
netuid = 1 # your created subnet's netuid

print(sub.weights(netuid=netuid))
```
Expand Down

0 comments on commit 9f29af1

Please sign in to comment.