- import os
...
+ import prefect
+ from prefect import Flow, Parameter, task
+ from prefect.client import Secret
+ from prefect.schedules import CronSchedule
+ @task
def get_standup_date():
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from google.cloud.firestore import Client | |
import os | |
import random | |
import requests | |
def get_standup_date(): | |
""" | |
Returns the current date, formatted, which maps |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%timeit -n 100 | |
_, _ = dask.compute(results['w_overlay'], | |
results['predict_another_thing']) | |
# 100 loops, best of 3: 1.61 ms per loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@delayed | |
def predict_another_thing(x, y, z): | |
# model scoring code goes here | |
pass | |
@delayed | |
def complicated_feature_b(x, y): | |
# lets imagine this feature is *very* expensive to create | |
# and takes a full minute to process |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dask import delayed | |
# won't be evaluated until we call .compute() | |
fast_predict_over_time = delayed(fast_predict_over_time) | |
## using the same numpy arrays from above... | |
%%timeit -n 100 | |
_ = fast_predict_over_time(x, y, z, False, res).compute() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res = np.zeros((n, 15)) | |
%%timeit -n 100 | |
_ = fast_predict_over_time(x, y, z, False, res) # 100 loops, best of 3: 575 µs per loop |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numba import guvectorize | |
@guvectorize('i8, f8, f8, b1, f8[:], f8[:]', | |
'(), (), (), (), (s) -> (s)') | |
def fast_predict_over_time(x, y, z, overlay, _, out): | |
adj = 1.5 if overlay else 1.0 | |
for t in range(len(out)): | |
out[t] = adj * (t * x ** 2 + y - 2 * z - 2 * t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numba import jit | |
@jit | |
def jitted_func(x, y, z, overlay=False): | |
"Predicts a quantity at times = 0, 1, ... 14" | |
out = np.zeros((x.shape[0], 15)) | |
for t in range(15): | |
out[:, t] = t * x ** 2 + y - 2 * z - 2 * t | |
adj = 1.5 if overlay else 1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def predict_over_time(x, y, z, overlay=False): | |
"Predicts a quantity at times = 0, 1, ... 14" | |
out = np.zeros((x.shape[0], 15)) | |
for t in range(15): | |
out[:, t] = t * x ** 2 + y - 2 * z - 2 * t | |
adj = 1.5 if overlay else 1.0 | |
return adj * out |