Skip to content

Instantly share code, notes, and snippets.

View ellisonbg's full-sized avatar

Brian E. Granger ellisonbg

View GitHub Profile
@ellisonbg
ellisonbg / binary_pi_digits.py
Created November 14, 2009 17:17
Functions for reading digits of pi in binary form
"""Functions for reading binary files with the digits of pi stored
as 4-bit ints."""
def bin_file_to_digits(filename, the_type=str):
raw_bytes = np.fromfile(filename, dtype=np.byte)
for b in raw_bytes[0:10000]:
digits = byte_to_digits(b)
yield the_type(digits[0])
yield the_type(digits[1])
@ellisonbg
ellisonbg / quantum_demo.py
Created October 27, 2010 05:05
Simple Demos for sympy.physics.quantum and friends
from sympy.physics.quantum import *
from sympy.physics.cartesian import *
from sympy.physics.piab import *
from sympy.physics.spin import *
# Basic manipulations with operators, bras, kets and commutators
psi, phi = Ket('psi'), Ket('phi')
psi, phi
A, B, C = Operator('A'), Operator('B'), Operator('C')
@ellisonbg
ellisonbg / physgraph.py
Created April 25, 2011 19:44
Quantum mechanics on graphs
"""Quantum mechanics on graphs.
Todo:
* Implement dirichlet boundary conditions.
* Use node attributes to label boundary points and impose dirichlet boundary
conditions.
* Develop plotting/viz routines using matplotlib/mayavi2.
* Use node attributes to store the physics coordinates of the point.
* Write a bisect function to put additional nodes between existing ones.
@ellisonbg
ellisonbg / diffusion1d.py
Created May 6, 2011 20:58
1D Diffusion Equation with FD+CN
"""Solve the 1D diffusion equation using CN and finite differences."""
from time import sleep
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
# The total number of nodes
nnodes = 10
# The total number of times
@ellisonbg
ellisonbg / gist:959768
Created May 6, 2011 20:58 — forked from thider/gist:956525
cranck nicholson stuck on BCs
from numpy import *
from matplotlib.pyplot import *
from time import sleep
import numpy as np
import networkx as nx
dim = [3,2]
@ellisonbg
ellisonbg / diffusion2d.py
Created May 10, 2011 15:16
2D Diffusion Equation with CN
"""Solve the 1D diffusion equation using CN and finite differences."""
from time import sleep
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
# The total number of nodes
numx = 5
numy = 5
"""Solve the 1D diffusion equation using CN and finite differences."""
from time import sleep
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
# The total number of nodes
nodx = 3
nody = 3
@ellisonbg
ellisonbg / Configuring the IPython.parallel
Created August 20, 2011 18:11
Running IPython.parallel on Microsoft Azure
============================
Configuring IPython.parallel
============================
This guide describes the steps needed to run IPython engines on Microsoft Azure to perform a parallel
computation in the Microsoft cloud. We assume (see above guide) that Python, IPython and PyZMQ have
been installed on a set of Azure compute nodes.
1. Install Python, IPython and PyZMQ on a system having open access to the internet. We used an
Ubuntu 11.04 system for this purpose. This system will run the IPython controller and the IPython
import networkx as nx
import matplotlib as mat
# Builds a graphene sheet with the given number of rows and columns.
# The sheet has a defected column running through the optionally passed
# arg. Otherwise it defaults to the center.
def build_defected_graph(rows, columns, defect = 0):
g = nx.Graph()
if( columns <= 2 ):
@ellisonbg
ellisonbg / d3.ipynb
Created February 16, 2012 01:32
How to use d3 with the IPython notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.