This file contains 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
#!/usr/bin/env python | |
""" | |
Allocate a GPUArray on one GPU in one process and copy it to | |
some other GPU in another process using IPC handles. | |
Notes | |
----- | |
Requires that the two GPUs support peer-to-peer data transfers. | |
""" |
This file contains 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
#!/usr/bin/env python | |
""" | |
Synchronize PUB/SUB sockets. | |
""" | |
import multiprocessing as mp | |
import time | |
import zmq |
This file contains 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
#!/usr/bin/env python | |
""" | |
How to use mpi4py with msgpack serialization | |
""" | |
from mpi4py import MPI | |
import msgpack | |
# mpi4py assumes that the serializer function takes more than one parameter: |
This file contains 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 inspect | |
import cProfile as profile | |
import wrapt | |
def prof(*dec_args, **dec_kwargs): | |
pr = profile.Profile() | |
if not dec_args or not inspect.isfunction(dec_args[0]): | |
@wrapt.decorator | |
def wrapper(wrapped, instance, args, kwargs): | |
pr.enable() |
This file contains 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
# Put this in your IPython profile configuration, e.g., ~/.ipython/profile_default/ipython_config.py | |
import os | |
extra = '' | |
if os.environ.has_key('VIRTUAL_ENV'): | |
v = os.path.basename(os.environ['VIRTUAL_ENV']) | |
extra += '<%s> ' % v | |
if os.environ.has_key('CONDA_DEFAULT_ENV'): | |
extra += '[%s] ' % os.environ['CONDA_DEFAULT_ENV'] |
This file contains 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
#!/usr/bin/env python | |
""" | |
How to create a class with an attribute that provides its own __getitem__() | |
method (similar to pandas.DataFrame.ix). | |
""" | |
class Indexer(object): | |
def __init__(self, data): | |
if not hasattr(data, '__getitem__') or not hasattr(data, '__setitem__'): |
This file contains 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
#!/usr/bin/env python | |
""" | |
How to find globals accessed by a Python object. | |
""" | |
import inspect | |
import numpy as np |
This file contains 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
#!/usr/bin/bin python | |
""" | |
How to use twiggy for logging in both parent and MPI-spawned processes. | |
""" | |
import sys | |
# Need to use dill to serialize the twiggy emitters because pickle can't handle | |
# them: |
This file contains 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
#!/usr/bin/env python | |
""" | |
Group of queues; data can be pushed/popped into each queue separately, but one | |
can also pop off values from all of the queues simultaneously. | |
+-------+ | |
queue a: in -> | |A|B| | |
+-------+ out -> (B,C) | |
queue b: in -> | |C| |
This file contains 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
#!/usr/bin/env python | |
""" | |
Morris-Lecar neurons connected by a conductance-based synapse. | |
""" | |
import numpy as np | |
import matplotlib | |
matplotlib.use('agg') |