Skip to content

Commit d308578

Browse files
Meetatgooglebronevet-abchrushikeshm-gabhinavprao
authored
Dev changes (#56)
* Restructured simulation analysis code made log extraction a single-binary operation * Small fixes to make remote trials work well with simulations and VM * fix * added metadata in tag of worker image * changed to cloud logger and some auto-format changes * more logging changes * Refinements * dsub local changes * proposal propose action outcome JSONified * sight.silent change and upgraded dsub * cloud log fix * incremental * formatter changes * more formatter changes * added setuptools explicit version * added changes in requirements.txt for different usecases * updated client dependencies with instruction of formatter * more * remove prints * Merged more * more merging * fix for dsub_local after stable merge * local setting for yapf formatter * handle ports related logic --------- Co-authored-by: Greg Bronevetsky <bronevet@google.com> Co-authored-by: hrushikeshm-g <hrushikeshm@google.com> Co-authored-by: Abhinav Rao <abhinavprao@google.com> Co-authored-by: bronevet-abc <75458629+bronevet-abc@users.noreply.github.com>
1 parent 51b2843 commit d308578

File tree

167 files changed

+9139
-7870
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+9139
-7870
lines changed

.config/.isort.cfg

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
profile = google
3+
use_parentheses = true
4+
line_length = 80
5+
multi_line_output = 3

.config/.style.yapf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[style]
2+
based_on_style = google
3+
indent_width = 2
4+
column_limit = 80

.config/setup.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yapf -ir -vv --style .config/.style.yapf .
2+
isort . --settings-path .config/ -v

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__pycache__
22
*.pyc
33
.env
4-
.vscode/
4+
.vscode/launch.json
55
*/.cache_local_data/*
66
*/.cache_redis_data/*
77
extra/*
8+
**/*.log

.pre-commit-config.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.0.1
4+
hooks:
5+
- id: trailing-whitespace
6+
exclude: ^.*\.patch$
7+
8+
- id: end-of-file-fixer
9+
exclude: ^.*\.patch$
10+
11+
- id: check-yaml
12+
13+
- repo: https://github.com/pre-commit/mirrors-yapf
14+
rev: v0.32.0
15+
hooks:
16+
- id: yapf
17+
args: ['--style', '.config/.style.yapf']
18+
19+
- repo: https://github.com/pre-commit/mirrors-isort
20+
rev: v5.10.1
21+
hooks:
22+
- id: isort
23+
args: ['--settings-path', '.config/.isort.cfg']

.vscode/settings.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"[python]": {
3+
"editor.formatOnSaveMode": "file",
4+
"editor.formatOnSave": true,
5+
"editor.formatOnType": true,
6+
"editor.defaultFormatter": "eeyore.yapf",
7+
},
8+
"python.analysis.typeCheckingMode": "off",
9+
"yapf.args": ["--style", "{based_on_style: Google, indent_width: 2, column_limit: 80}"],
10+
}
11+

README.md

+68-11
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ cd venvs
141141
virtualenv sight_env --python=python3.10
142142
source ~/venvs/sight_env/bin/activate
143143

144-
# Install necessary dependencies from requirement.txt file
144+
# Install setup.py compatible setuptools and necessary dependencies from requirement.txt file
145+
pip install setuptools==58.2.0
145146
pip install -r ~/x-sight/py/sight/requirements.txt
146147
```
147148
Note : if error ```ModuleNotFoundError: No module named 'virtualenv'``` occurs, try installing virtualenv using pip,
@@ -155,6 +156,64 @@ source ~/venvs/sight_env/bin/activate
155156
cd ~/x-sight
156157
```
157158

159+
#### Setup yapf in vscode
160+
161+
add extention eeyore.yapf in vscode.
162+
add .vscode folder in the repo and create settings.json file which will override the defauls settings of the vscode
163+
add following code snippet there or change accordingly if you already have custom setting
164+
165+
```
166+
{
167+
"[python]": {
168+
"editor.formatOnSaveMode": "file",
169+
"editor.formatOnSave": true,
170+
"editor.formatOnType": true,
171+
"editor.defaultFormatter": "eeyore.yapf",
172+
},
173+
"python.analysis.typeCheckingMode": "off",
174+
"yapf.args": ["--style", "{based_on_style: Google, indent_width: 2, column_limit: 80}"],
175+
}
176+
```
177+
you might need to restart vscode to see the changes
178+
179+
If you are setting up this first time and want to apply this style to existing repo
180+
create .config folder in the repo
181+
182+
1. Create .style.yapf file with following content in .config folder
183+
```
184+
[style]
185+
based_on_style = google
186+
indent_width = 2
187+
column_limit = 80
188+
```
189+
190+
2. Create .isort.cfg file with following content in .config folder
191+
```
192+
[settings]
193+
profile = google
194+
use_parentheses = true
195+
line_length = 80
196+
multi_line_output = 3
197+
```
198+
199+
run the following commands from root folder of the repo to apply those style changes
200+
```
201+
yapf -ir -vv --style .config/.style.yapf .
202+
isort . --settings-path .config/ -v
203+
```
204+
#### setup pre-commit hook
205+
206+
207+
this pre-commit hook checks for the same formatting style we just setup locally
208+
```
209+
pip install pre-commit
210+
```
211+
212+
- make sure you created .style.yapf and .isort.cfg file in .config folder from the previous step.
213+
- make sure your repo contains .pre-commit-config.yaml file in root directory of repo
214+
215+
216+
158217
### User Permissions:
159218

160219
Note : all the follow up commands using $PROJECT_ID assumes you have it already set to your gcp project id. If not, set it via
@@ -247,11 +306,9 @@ account can have required permissions.
247306
2) Create service image from the code and host it on [gcr.io](http://gcr.io)
248307

249308
```bash
250-
docker build --tag gcr.io/$PROJECT_ID/sight-default -f sight_service/Dockerfile .
251-
252-
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
253-
254-
docker push gcr.io/$PROJECT_ID/sight-default
309+
docker build --tag gcr.io/$PROJECT_ID/sight-default:$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD) -f sight_service/Dockerfile . && \
310+
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io && \
311+
docker push gcr.io/$PROJECT_ID/sight-default:$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)
255312
```
256313

257314
3) With the help of the image, launch cloud run service
@@ -266,11 +323,9 @@ Host the worker image in a cloud which will be used as default image by the
266323
workers spawned using sight unless specified otherwise.
267324

268325
```bash
269-
docker build --tag gcr.io/$PROJECT_ID/sight-worker -f py/Dockerfile .
270-
271-
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
272-
273-
docker push gcr.io/$PROJECT_ID/sight-worker
326+
docker build --tag gcr.io/$PROJECT_ID/sight-worker:$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD) -f py/Dockerfile . && \
327+
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io && \
328+
docker push gcr.io/$PROJECT_ID/sight-worker:$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)
274329
```
275330

276331
## Logging API
@@ -763,3 +818,5 @@ cd ~/x-sight
763818
python sight_service/service_root.py
764819
```
765820
And from another terminal session, User can run any valid command from [this](#example-training-invocation-commands) section and change the flag ```--deployment_mode=local``` to indicate that sight_service is running locally.
821+
822+

fvs_sight/fvs_api.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Any
2+
23
from sight.proto import sight_pb2
34

45
FVS_PARAMS = {
@@ -26,8 +27,8 @@ def create_attr_props(
2627
"""
2728
return {
2829
key: (sight_pb2.DecisionConfigurationStart.AttrProps() if value
29-
is not None else sight_pb2.DecisionConfigurationStart.AttrProps())
30-
for key, value in config_dict.items()
30+
is not None else sight_pb2.DecisionConfigurationStart.AttrProps()
31+
) for key, value in config_dict.items()
3132
}
3233

3334

@@ -58,6 +59,7 @@ def get_action_attrs():
5859
action_config.update(expand_params_for_cycles(fvs_params=FVS_PARAMS))
5960
return create_attr_props(action_config)
6061

62+
6163
# action_attrs = {
6264
# "a1":
6365
# sight_pb2.DecisionConfigurationStart.AttrProps(
@@ -77,13 +79,13 @@ def get_action_attrs():
7779
# }
7880

7981

80-
8182
def get_outcome_attrs():
8283
"""Returns the outcome attributes for the FVS outcome.
8384
"""
8485
outcome_config = {'time_series': None}
8586
return create_attr_props(outcome_config)
8687

88+
8789
# outcome_attrs = {
8890
# "time_series":
8991
# sight_pb2.DecisionConfigurationStart.AttrProps(

fvs_sight/fvs_sight_worker.py

+31-39
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
2-
import yaml
1+
import json
2+
import os
3+
from typing import Sequence
34

45
from absl import app
56
from absl import flags
6-
from sight.widgets.decision import decision_episode_fn
77
# from fvs_sight.fvs_api import action_attrs, outcome_attrs
88
from fvs_sight import fvs_api
9-
9+
import pandas as pd
1010
from sight import data_structures
1111
from sight.proto import sight_pb2
1212
from sight.sight import Sight
1313
from sight.widgets.decision import decision
14-
from typing import Sequence
15-
import os
16-
import pandas as pd
17-
import json
14+
from sight.widgets.decision import decision_episode_fn
1815
import yaml
1916

2017

21-
def simulate_fvs(sight,params_dict):
22-
print('here params_dict is :', params_dict)
23-
mitigation_list = [227.6, 273.4, 273.3, 248.6, 165.3, 130.6, 106.4, 92.1, 81.7, 62.8]
24-
sim_stream = pd.Series(mitigation_list)
25-
# print(sim_stream)
26-
return sim_stream
18+
def simulate_fvs(sight, params_dict):
19+
print('here params_dict is :', params_dict)
20+
mitigation_list = [
21+
227.6, 273.4, 273.3, 248.6, 165.3, 130.6, 106.4, 92.1, 81.7, 62.8
22+
]
23+
sim_stream = pd.Series(mitigation_list)
24+
# print(sim_stream)
25+
return sim_stream
26+
2727

2828
def driver_fn(sight):
2929

@@ -34,9 +34,9 @@ def driver_fn(sight):
3434
# return None
3535
# raise SystemError
3636

37-
sim_stream = simulate_fvs(sight,params_dict)
37+
sim_stream = simulate_fvs(sight, params_dict)
3838

39-
outcome = {'time_series' : sim_stream}
39+
outcome = {'time_series': sim_stream}
4040
print("outcome : ", outcome)
4141

4242
decision.decision_outcome('outcome_label', sight, reward=0, outcome=outcome)
@@ -45,32 +45,24 @@ def driver_fn(sight):
4545

4646
#temporary created
4747
def get_sight_instance():
48-
params = sight_pb2.Params(
49-
label="kokua_experiment",
50-
bucket_name=f'{os.environ["PROJECT_ID"]}-sight',
51-
)
52-
sight_obj = Sight(params)
53-
return sight_obj
48+
params = sight_pb2.Params(
49+
label="kokua_experiment",
50+
bucket_name=f'{os.environ["PROJECT_ID"]}-sight',
51+
)
52+
sight_obj = Sight(params)
53+
return sight_obj
5454

5555

5656
def main(argv: Sequence[str]) -> None:
57-
if len(argv) > 1:
58-
raise app.UsageError("Too many command-line arguments.")
59-
60-
with get_sight_instance() as sight:
61-
decision.run(
62-
driver_fn=driver_fn,
63-
sight=sight,
64-
action_attrs=fvs_api.get_action_attrs(),
65-
outcome_attrs=fvs_api.get_outcome_attrs()
66-
)
67-
68-
if __name__ == "__main__":
69-
app.run(main)
70-
71-
72-
73-
57+
if len(argv) > 1:
58+
raise app.UsageError("Too many command-line arguments.")
7459

60+
with get_sight_instance() as sight:
61+
decision.run(driver_fn=driver_fn,
62+
sight=sight,
63+
action_attrs=fvs_api.get_action_attrs(),
64+
outcome_attrs=fvs_api.get_outcome_attrs())
7565

7666

67+
if __name__ == "__main__":
68+
app.run(main)

0 commit comments

Comments
 (0)