Skip to content

Instantly share code, notes, and snippets.

View edoakes's full-sized avatar

Edward Oakes edoakes

  • Anyscale
  • Minneapolis, MN
View GitHub Profile
@edoakes
edoakes / monte_carlo_pi.py
Last active February 8, 2020 00:26
Monte Carlo Pi Estimation in Python
import math
import random
import time
def sample(num_samples):
num_inside = 0
for _ in range(num_samples):
x, y = random.uniform(-1, 1), random.uniform(-1, 1)
if math.hypot(x, y) <= 1:
num_inside += 1
@edoakes
edoakes / parallel_monte_carlo_pi.py
Last active February 8, 2020 01:10
Monte Carlo Pi Estimation in Python - parallel using multiprocessing.Pool
import math
import random
import time
def sample(num_samples):
num_inside = 0
for _ in range(num_samples):
x, y = random.uniform(-1, 1), random.uniform(-1, 1)
if math.hypot(x, y) <= 1:
num_inside += 1
import math
import random
import time
def sample(num_samples):
num_inside = 0
for _ in range(num_samples):
x, y = random.uniform(-1, 1), random.uniform(-1, 1)
if math.hypot(x, y) <= 1:
num_inside += 1
import requests
from ray import serve
serve.init()
# Main concepts
## Endpoints
import ray
from ray import serve
# Connect to the running Ray Serve instance.
ray.init(address='auto', ignore_reinit_error=True)
serve.init()
# Deploy the model.
serve.create_backend("sklearn_backend", SKLearnBackend)
serve.create_endpoint("sentiment_endpoint", backend="sklearn_backend", route="/sentiment")
import requests
input_text = "Ray Serve eases the pain of model serving"
result = requests.get("http://127.0.0.1:8000/sentiment", data=input_text).text
print("Result for '{}': {}".format(input_text, result))
This file has been truncated, but you can view the full file.
This time, a new baby is on the way, and it's a girl. Wrapped together with the standard conflict between mother and father, Mikey engages in a bit of sibling rivalry with his new sister.
Excited with the arrival of their baby girl, Julie, the happy couple of James, the cab driver, and Molly, the accountant, will have to prepare young Mikey for the role of the big brother. Against the backdrop of rigorous potty training, heated arguments, and, first and foremost, healthy sibling rivalry, both adults and children alike will learn that family is above all. Will Julie follow in Mikey's footsteps?
Mollie and James are together and raising a family, which now consists of an older Mikey and his baby sister, Julie. Tension between the siblings arises, and as well with Mollie and James when Mollie's brother Stuart moves in. Mikey is also learning how to use the toilet for the first time.
Excited with the arrival of their baby girl, Julie, the happy couple of James, the cab driver, and Molly, the accountant, will have
@edoakes
edoakes / pass_by_ref.py
Last active October 22, 2020 19:59
Ray Serve by reference vs. pass by value experiment
import time
import numpy as np
import ray
ray.init(log_to_driver=False)
@ray.remote
class Actor:
def __init__(self, next_actor, by_ref):
@edoakes
edoakes / mp.py
Last active November 20, 2020 21:00
import math
import random
import time
from multiprocessing.pool import Pool
NUM_SAMPLES = 100000000
NUM_PROCESSES = 8
def take_sample(index):
import asyncio
from asyncio.futures import Future
from collections import defaultdict
from typing import Dict, Any, List, Optional, Set, Tuple
import ray
import ray.cloudpickle as pickle
from ray.actor import ActorHandle
from ray.serve.async_goal_manager import AsyncGoalManager
from ray.serve.backend_worker import create_backend_replica