Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions dask/Apppendix-A.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
# In[ ]:





# In[1]:


Expand All @@ -31,7 +28,3 @@


# In[ ]:




78 changes: 22 additions & 56 deletions dask/Dask-Ch10_porting.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
# In[ ]:





# In[ ]:


Expand All @@ -60,17 +57,15 @@

client = Client(cluster)

cluster.adapt(minimum_jobs=10, maximum_jobs=100) # auto-scale between 10 and 100 jobs
# auto-scale between 10 and 100 jobs
cluster.adapt(minimum_jobs=10, maximum_jobs=100)
cluster.adapt(maximum_memory="10 TB") # or use core/memory limits
#end::ex_slurm_deployment[]


# In[ ]:





# In[ ]:


Expand All @@ -92,12 +87,12 @@
df.to_parquet(f's3://s3_destination/{filename}',
compression="gzip",
storage_options=minio_storage_options,
engine = "fastparquet")
engine="fastparquet")


df = dd.read_parquet(
f's3://s3_source/',
storage_options=minio_storage_options,
f's3://s3_source/',
storage_options=minio_storage_options,
engine="pyarrow"
)
#end::ex_s3_minio_rw[]
Expand All @@ -106,9 +101,6 @@
# In[ ]:





# In[ ]:


Expand All @@ -120,15 +112,9 @@
# In[ ]:





# In[ ]:





# In[ ]:


Expand All @@ -141,15 +127,9 @@
# In[ ]:





# In[ ]:





# In[ ]:


Expand All @@ -169,9 +149,6 @@
# In[ ]:





# In[ ]:


Expand All @@ -193,7 +170,7 @@

setup(is_lab=True)

%%fsql dask
% % fsql dask

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

breaking change but this ex is not included as .py so ok

tempdf = SELECT VendorID, AVG(total_amount) AS average_fare FROM df GROUP BY VendorID

SELECT *
Expand All @@ -207,9 +184,6 @@
# In[ ]:





# In[ ]:


Expand All @@ -222,21 +196,21 @@
# In[ ]:


get_ipython().run_cell_magic('fsql', 'dask', 'tempdf = SELECT VendorID, AVG(total_amount) AS average_fare FROM df GROUP BY VendorID\n\nSELECT *\nFROM tempdf\nORDER BY average_fare DESC\nLIMIT 5\nPRINT')
get_ipython().run_cell_magic(
'fsql',
'dask',
'tempdf = SELECT VendorID, AVG(total_amount) AS average_fare FROM df GROUP BY VendorID\n\nSELECT *\nFROM tempdf\nORDER BY average_fare DESC\nLIMIT 5\nPRINT')


# In[ ]:





# In[ ]:


#tag::ex_postgres_dataframe[]
df = dd.read_sql_table('accounts', 'sqlite:///path/to/your.db',
npartitions=10, index_col='id')
npartitions=10, index_col='id')
#end::ex_postgres_dataframe[]


Expand All @@ -247,23 +221,17 @@
from dask.distributed import Client

client = Client()
client.log_event(topic = "custom_events", msg = "hello world")
client.log_event(topic="custom_events", msg="hello world")
client.get_events("custom_events")
#end::ex_basic_logging[]


# In[ ]:





# In[ ]:





# In[ ]:


Expand Down Expand Up @@ -296,7 +264,8 @@
d = {'x': [3.0, 1.0, 0.2], 'y': [2.0, 0.5, 0.1], 'z': [1.0, 0.2, 0.4]}
scores_df = dd.from_pandas(pd.DataFrame(data=d), npartitions=1)

def compute_softmax(partition, axis = 0):

def compute_softmax(partition, axis=0):
""" computes the softmax of the logits
:param logits: the vector to compute the softmax over
:param axis: the axis we are summing over
Expand All @@ -312,9 +281,11 @@ def compute_softmax(partition, axis = 0):
ret = e / np.sum(e, axis=axis)
stop = timeit.default_timer()
# partition.log_event("softmax", {"start": start, "x": x, "stop": stop})
dask.distributed.get_worker().log_event("softmax", {"start": start, "input": x, "stop": stop})
dask.distributed.get_worker().log_event(
"softmax", {"start": start, "input": x, "stop": stop})
return ret


scores_df.apply(compute_softmax, axis=1, meta=object).compute()
client.get_events("softmax")
#end::ex_distributed_logging[]
Expand All @@ -323,9 +294,6 @@ def compute_softmax(partition, axis = 0):
# In[ ]:





# In[ ]:


Expand All @@ -336,7 +304,7 @@ def compute_softmax(partition, axis = 0):


# plain version of the function
def compute_softmax(x, axis = 0):
def compute_softmax(x, axis=0):
""" computes the softmax of the logits
:param logits: the vector to compute the softmax over
:param axis: the axis we are summing over
Expand All @@ -348,20 +316,18 @@ def compute_softmax(x, axis = 0):
e = np.exp(x - np.max(x))
ret = e / np.sum(e, axis=axis)
stop = timeit.default_timer()
dask.distributed.get_worker().log_event("softmax", {"start": start, "x": x, "stop": stop})
dask.distributed.get_worker().log_event(
"softmax", {"start": start, "x": x, "stop": stop})
return ret

scores_df.apply(compute_softmax, axis = 1, meta = object).compute()


# In[ ]:

scores_df.apply(compute_softmax, axis=1, meta=object).compute()


# In[ ]:


# In[ ]:


client.close()

Loading