-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
58 lines (46 loc) · 1.53 KB
/
client.py
File metadata and controls
58 lines (46 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import requests
import numpy as np
######### DO NOT CHANGE ANYTHING IN THIS FILE ##################
API_ENDPOINT = 'http://10.4.21.147'
PORT = 3000
MAX_DEG = 11
#### functions that you can call
def get_errors(id, vector):
"""
returns python array of length 2
(train error and validation error)
"""
for i in vector: assert -10<=abs(i)<=10
assert len(vector) == MAX_DEG
return json.loads(send_request(id, vector, 'geterrors'))
def submit(id, vector):
"""
used to make official submission of your weight vector
returns string "successfully submitted" if properly submitted.
"""
for i in vector: assert -10<=abs(i)<=10
assert len(vector) == MAX_DEG
return send_request(id, vector, 'submit')
#### utility functions
def urljoin(root, port, path=''):
root = root + ':' + str(port)
if path: root = '/'.join([root.rstrip('/'), path.rstrip('/')])
return root
def send_request(id, vector, path):
api = urljoin(API_ENDPOINT, PORT, path)
vector = json.dumps(vector)
response = requests.post(api, data={'id':id, 'vector':vector}).text
if "reported" in response:
print(response)
exit()
return response
if __name__ == "__main__":
"""
Replace "test" with your secret ID and just run this file
to verify that the server is working for your ID.
"""
err = get_errors('test', list(-np.arange(0,1.1,0.1)))
assert len(err) == 2
submit_status = submit('test', list(-np.arange(0,1.1,0.1)))
assert "submitted" in submit_status