Skip to content

Commit

Permalink
changes to subspace
Browse files Browse the repository at this point in the history
  • Loading branch information
latentvector committed Jun 7, 2024
1 parent 1b57202 commit 9c22ba5
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 52 deletions.
7 changes: 2 additions & 5 deletions commune/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2477,20 +2477,17 @@ def serve(cls,
'kwargs':kwargs
}

c.print(module, name)
module_class = c.module(module)

kwargs.update(extra_kwargs)

if mnemonic != None:
c.add_key(server_name, mnemonic)

self = module_class(**kwargs)
self.server_name = name
self.tag = tag

address = c.get_address(name, network=server_network)
if address != None and ':' in address:
port = address.split(':')[-1]


if c.server_exists(server_name, network=server_network) and not refresh:
return {'success':True, 'message':f'Server {server_name} already exists'}
Expand Down
14 changes: 9 additions & 5 deletions commune/subspace/subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ def get_substrate(self,


def set_network(self,
network:str = 'main',
network:str = None,
mode = 'http',
trials = 10,
url : str = None,
**kwargs):
self.network = self.config.network = network or self.config.network
self.substrate = self.get_substrate(network=network, url=url, mode=mode, trials=trials , **kwargs)
response = {'network': self.network, 'url': self.url}

Expand Down Expand Up @@ -1307,14 +1308,17 @@ def balances(self,fmt:str = 'n', network:str = network, block: int = None, n = N
return balances


def resolve_network(self, network: Optional[int] = 'subspace:main',
new_connection =False,
only_name = False,
mode='ws', **kwargs) -> int:
def resolve_network(self,
network: Optional[int] = 'subspace:main',
spliters: List[str] = [':', '::'],
**kwargs) -> int:
"""
Resolve the network to use for the current session.
"""
for spliter in spliters:
if spliter in str(network):
network = network.split(spliter)[-1]
network = network or self.config.network
return network

Expand Down
7 changes: 7 additions & 0 deletions commune/subspace/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def test_module_params(self, keys=['dividends', 'incentive'], netuid=0):
return {'msg': 'module_params test passed', 'success': True, 'module_info': module_info}


def test_substrate(self):
for i in range(3):
t1 = c.time()
c.print(c.module('subspace')().substrate)
t2 = c.time()
c.print(f'{t2-t1:.2f} seconds')




Expand Down
45 changes: 21 additions & 24 deletions commune/vali/vali.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,26 @@ def init_vali(self, config=None, module=None, score_fn=None, **kwargs):
config = self.set_config(config, kwargs=kwargs)
config = c.dict2munch({**Vali.config(), **config})
config.verbose = bool(config.verbose or config.debug)
c.print(f'Initialized Vali with {config}', color='yellow')
self.config = config
self.set_score_fn(score_fn)
self.futures = []
# COUNT METRICS
self.requests = 0
self.errors = 0
self.successes = 0
self.epochs = 0
self.staleness_count = 0
# timestamp metrics
self.last_sync_time = 0
self.last_error = 0
self.last_sent = 0
self.last_success = 0

self.init_state()
self.config = config
c.print(self.sync())
c.thread(self.run_loop)

def init_state(self):
self.futures = [] # futures for the executor
# COUNT METRICS
self.requests = 0 # the number of requests
self.errors = 0 # the number of errors
self.successes = 0 # the number of successes
self.epochs = 0 # the number of epochs
self.staleness_count = 0 # the number of staleness
# timestamp metrics
self.last_sync_time = 0 # the last time the network was synced
self.last_error = 0 # the last time an error occured
self.last_sent = 0 # the last time a request was sent
self.last_success = 0 # the last time a success was made

init = init_vali

@property
Expand Down Expand Up @@ -238,12 +239,11 @@ def is_voting_network(self):

def filter_module(self, module:str, search=None):
search = search or self.config.search
if ',' in search:
if ',' in str(search):
search_list = search.split(',')
else:
search_list = [search]

return all([s in module for s in search_list])
return all([s == None or s in module for s in search_list ])


def sync_network(self,
Expand Down Expand Up @@ -449,9 +449,8 @@ def process_response(self, response:dict, info:dict ):

def storage_path(self, network=None):
# the set storage path in config.path is set, then the modules are saved in that directory
if self.config.get('path', None) != None:
path = self.config.path
else:
path = self.config.get('path', None) or self.config.get('storage_path', None)
if path == None:
network = network or self.config.network
if 'subspace' in network:
network_str = f'{network}.{self.config.netuid}'
Expand All @@ -472,15 +471,13 @@ def vote_info(self):
except Exception as e:
votes = {'uids': [], 'weights': []}
c.print(c.detailed_error(e))
info = {
return {
'num_uids': len(votes.get('uids', [])),
'staleness': self.vote_staleness,
'key': self.key.ss58_address,
'network': self.config.network,
}

return info

def calculate_votes(self, df=None, **kwargs):
network = self.config.network
keys = ['name', 'w', 'staleness','latency', 'key']
Expand Down
2 changes: 1 addition & 1 deletion commune/vali/vali.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ print_interval: 5
sample_interval: 0.1
search: null
start: true
sync_interval: 100
sync_interval: 1000
threads_per_worker: 64
timeout: 10
timeout_info: 4
Expand Down
27 changes: 10 additions & 17 deletions docs/blackpaper/1_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@ I am not the best at writing as I see ideas and its hard for me to put them down

The Module

A module can represent everything as it is turing complete. This means a module can represent any idea, like an ai model, to a business, to a student loan. In code terms, a module is a simple class in python, where it is a collection of functions that change a state. This general definition is the core foundation of the module.

The Module is Simple and Complex?

Like a python class (to whic we try to maximally mimic as much as possible), a module can represent a simple idea like a function, or a complex idea like a business. This allows for a flexible network that can adapt to different use cases. The module is the core abstract that allows for a flexible network that can adapt to different use cases. This is becuase the module is turing complete, and can represent any idea.

Module Key

Each module is represented as a key which is an sr25519 key. The public key is used to register the module onto the blockchain. The key is used to sign, encrypt,decrypt and verify messages. These keys can also represent other keys on any other chain through transfering its seed entropy to another chain key format. This allows for modules to exist on any chain

![Alt text](image_module_key.png)

For Warning for Anti-Python Peeps

The module is designed from a python class, but this can be implemented in rust, javascript, or any other language, even if they are functional programming languages (via structs). You can think of the module as a class in any language, where it is a collection of functions that change a state. This is the core foundation of the module.
A module is a bundle of functions with a state, which resembles the python class at its design. This means a module can represent any idea, like an ai model, to a business, a blockchain, anything. It can have its own identity and state, remember interactions, and can be served as an api. The module is a general turing complete process that is made accessible to people.

This is a simple example of a module that says whadup.

```python
import commune as c
class Model(c.Module):
class Adder(c.Module):
def __init__(self, c=0):
self.c = c

Expand All @@ -35,10 +21,17 @@ class Model(c.Module):
![Alt text](image_module.png)


Module Key

Each module is represented as a key which is an sr25519 key. The public key is used to register the module onto the blockchain. The key is used to sign, encrypt,decrypt and verify messages. These keys can also represent other keys on any other chain through transfering its seed entropy to another chain key format. This allows for modules to exist on any chain

![Alt text](image_module_key.png)


I can serve this as an api which runs in the background

```python
c.serve(Whadup, name="mode_model")
c.serve(Adder, name="mode_model")
```

calling whadup/ function and it will return a + b + c as defined inside the function.
Expand Down

0 comments on commit 9c22ba5

Please sign in to comment.