-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexamples.py
More file actions
42 lines (29 loc) · 1.63 KB
/
examples.py
File metadata and controls
42 lines (29 loc) · 1.63 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
from codegreen.decorators import init_experiment, time_shift, upload_cc_report
from codecarbon import track_emissions
from codegreen.queries import get_location_prediction, get_data
import numpy as np
from datetime import datetime
# Complete example to timeshift the computation, monitor the energy consumption using codecarbon and then upload the report.
#A. decorate the function
#@init_experiment(estimated_runtime_hours=1,estimated_runtime_minutes=30,percent_renewable=40,allowed_delay_hours= 24, area_code=["DE-9"],log_request=True,experiment_name="my_experiment",codecarbon_logfile="experiment.log",nextflow_logfile="nextflow.log",overwrite=True)
@init_experiment(experiment_name="my_experiment")
@time_shift("my_experiment")
@upload_cc_report("my_experiment")
@track_emissions(output_file='experiment.log')
def hello_random_matrix_generator():
for _ in range(1000):
np.random.random((1000, 1000))
print("Hello")
#B. run the function
hello_random_matrix_generator()
# Download the data you submitted.
data = get_data('codecarbon', False, 'my_experiment')
# Get a location prediction.
location = get_location_prediction(estimated_runtime_hours = 1,
estimated_run_time_in_minutes=12,
percent_renewable=40,
hard_finish_time = datetime.utcnow().replace(hour=18, minute=0, second=0).timestamp(),
area_code = ['DE-79117', 'CY-1', 'CZ-8'],
log_request = True,
process_id = '1',
experiment_name='my_experiment')