Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Commit 1bd53a1

Browse files
author
rogervs
committed
Fleshing out README.md
1 parent ebc080e commit 1bd53a1

File tree

2 files changed

+168
-8
lines changed

2 files changed

+168
-8
lines changed

README.md

+73-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cadCAD Golem
22

3-
## Work in progress - due date 5 January 2021
3+
## Work in progress - due date 5 January 2021 - [https://gitcoin.co/issue/golemfactory/hackathons/3/100024408]
44

55
This package is a wrapper for cadCAD to dispatch the simulation workload to multiple Golem nodes.
66

@@ -24,17 +24,82 @@ source .venv/bin/activate
2424

2525
Now you have an isolated environment where you can install your python packages without fear of bloating the rest of your system.
2626

27-
### Installing
27+
### Install cadcadgolem
2828
Requires [>= Python 3.8](https://www.python.org/downloads/)
2929

30-
**Option A: Install Using [pip](https://pypi.org/project/cadCAD/)**
30+
#### Install Using [pip](https://pypi.org/project/cadCAD/)**
3131
```bash
32-
$ pip3 install cadcadgolem
32+
$ pip3 install *cadcadgolem*
3333
```
3434

35-
**Option B:** Build From Source
35+
### Install *yagna daemon*
36+
37+
The Yagna daemon is what you will use to interface with the Golem network. It runs in the background, waiting for API calls from your applications, in our case, from *cadcadgolem*.
38+
39+
To install yagna, you can use their helper script:
40+
```
41+
curl -sSf https://join.golem.network/as-requestor | bash -
42+
```
43+
44+
For manual installation instructions, see: [https://handbook.golem.network/requestor-tutorials/flash-tutorial-of-requestor-development]
45+
46+
To check it is installed corretly, run:
47+
```
48+
yagna --version
49+
```
50+
51+
### Prepare *yagna daemon*
52+
To run the yagna daemon, follow the following sequence. This sequence will need to be followed everytime you restart *yagna*.
53+
54+
#### Start the daemon
55+
This will initialise the daemon
56+
```
57+
yagna service run
58+
```
59+
60+
#### Generate the app key
3661
```
37-
$ pip3 install -r requirements.txt
38-
$ python3 setup.py sdist bdist_wheel
39-
$ pip3 install dist/*.whl
62+
yagna app-key create requestor
4063
```
64+
65+
This should produce a 32-character-long hexadecimal app key that you need to note down as it will be needed in your code to run the requestor agent.
66+
67+
#### Get some coinage
68+
Golem currently has a faucit where you can get free tokens to pay for the processing that you will perform on the network.
69+
```
70+
yagna payment init -r
71+
```
72+
73+
#### Check that the fund transfer was successfull.
74+
```
75+
yagna payment status
76+
```
77+
78+
#### Add your app-key to your code
79+
When using cadcadgolem, a dictionary is passed that contains the parameters for your interaction with the network. One of them is yor app-eky, which allows you to speak to the *yagna* daemon that you started earlier. Place your app-key into your dictionary (see dictionary below).
80+
81+
## Using cadcad Golem
82+
83+
To use cadcad Golem, you need to do two things:
84+
1. Define the golem_conf dictionary:
85+
```
86+
golem_conf = {
87+
'NODES': 3, # Number of nodes to utilise from the Golem Network
88+
'BUDGET': 10.0, # Maximum amount of crypto you are prepared to spend
89+
'SUBNET': "community.3", # choose your subnet, currently this is the test network
90+
'YAGNA_APPKEY': '<YOUR-YAGNA_APPKEY-GOES HERE>', # get this from `yagna app-key list`
91+
'TIMEOUT': 120 # In seconds
92+
}
93+
```
94+
(Example)[https://github.com/rogervs/cadcad_models/blob/2e61a84d1f28b23a3e0e9ef01f3c1f4fd4c85b2d/simple_cadcad.py#L75-L81]
95+
96+
2. Wrap your cadcad `Executor` in the cadcad Golem `Ambassador`:
97+
```
98+
Executor = Ambassador(Executor, golem_conf)
99+
```
100+
(Example)[https://github.com/rogervs/cadcad_models/blob/2e61a84d1f28b23a3e0e9ef01f3c1f4fd4c85b2d/simple_cadcad.py#L83]
101+
102+
For a simple cadCAD implementation, see (simple_cadcad.py)[https://github.com/rogervs/cadcad_models/blob/master/simple_cadcad.py]
103+
104+
## Security Notice
105+
The communication on the Golem network is currently not encrypted, so do not use this for any sensitive data.

simple_cadcad.py

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import numpy as np
2+
from cadCAD.configuration import Experiment
3+
from cadCAD.configuration.utils import config_sim
4+
from cadCAD.configuration import Configuration
5+
from cadCAD.engine import ExecutionMode, ExecutionContext, Executor
6+
import pandas as pd
7+
from cadcadgolem.golem_embassy import Ambassador
8+
9+
def p_something(params,
10+
substep,
11+
state_history,
12+
prev_state):
13+
parameter = params['parameter']
14+
random_value_1 = np.random.randn() + parameter
15+
random_value_2 = np.random.rand() + parameter
16+
return {'policy_input_1': random_value_1,
17+
'policy_input_2': random_value_2}
18+
19+
20+
def s_something(params,
21+
substep,
22+
state_history,
23+
prev_state,
24+
policy_input):
25+
new_value = policy_input['policy_input_1']
26+
new_value += policy_input['policy_input_2']
27+
return ('something', new_value)
28+
29+
30+
partial_state_update_blocks = [
31+
{
32+
'policies': {
33+
'something': p_something
34+
35+
},
36+
'variables': {
37+
'something': s_something
38+
}
39+
}
40+
]
41+
42+
from cadCAD import configs
43+
del configs[:]
44+
45+
MONTE_CARLO_RUNS = 20
46+
SIMULATION_TIMESTEPS =200
47+
48+
sys_params = {
49+
'parameter': [0.1, 0.2, 0.3],
50+
}
51+
52+
genesis_states = {
53+
'something': 0
54+
}
55+
56+
57+
sim_config = {
58+
'N': MONTE_CARLO_RUNS,
59+
'T': range(SIMULATION_TIMESTEPS),
60+
'M': sys_params
61+
}
62+
63+
sim_params = config_sim(sim_config)
64+
65+
exp = Experiment()
66+
exp.append_configs(
67+
sim_configs=sim_params,
68+
initial_state=genesis_states,
69+
partial_state_update_blocks=partial_state_update_blocks
70+
)
71+
72+
73+
74+
75+
golem_conf = {
76+
'NODES': 3, # Number of nodes to utilise from the Golem Network
77+
'BUDGET': 10.0, # Maximum amount of crypto you are prepared to spend
78+
'SUBNET': "community.3", # choose your subnet, currently this is the test network
79+
'YAGNA_APPKEY': '856340c2e28f4c4ab0def44d09306439', # get this from `yagna app-key list`
80+
'TIMEOUT': 120 # In seconds
81+
}
82+
83+
Executor = Ambassador(Executor, golem_conf)
84+
exec_context = ExecutionContext(context=ExecutionMode.single_mode )
85+
simulation = Executor(exec_context=exec_context, configs=configs)
86+
#simulation = Executor(exec_context=local_mode_ctx, configs=configs)
87+
88+
89+
raw_system_events, tensor_field, sessions = simulation.execute()
90+
91+
df = pd.DataFrame(raw_system_events)
92+
93+
94+
print(df)
95+

0 commit comments

Comments
 (0)