Tuesday, November 4, 2014

latexdiff

Latex is great for making beautiful papers and OK for version control. But, collaborating can be as tough as ever. One great tool for comparing drafts in latexdiff.

I found these directions particularly helpful for using latexdiff: https://www.sharelatex.com/blog/2013/02/16/using-latexdiff-for-marking-changes-to-tex-documents.html. In particular, this is the line I will need to use over and over again:

latexdiff draft.tex revision.tex > diff.tex


Thursday, June 12, 2014

Cluster Coordinates

My PhD research is on clusters of tiny little spheres. I often need to compute things for the spheres in specific configurations. I usually just figure out the coordinates each time. BUT, now I'm posting the most common configurations here, so that I can just look them up here. In python array format. The sphere diameter is assumed to be 1, and the center of each cluster is at the origin.

import numpy as np

single_coords = np.array(
       [0,0,0])

dimer_coords = np.array([
       [-.5,0,0],
       [.5,0,0]])

line_coords = np.array([
       [-1.,0,0],
       [0,0,0],
       [1.,0,0]])

tri_coords = np.array([
       [sqrt(3)/6.,-.5,0],
       [sqrt(3)/6., .5,0],
       [-sqrt(3)/3.,0,0]])

dia_coords = np.array([
       [0,-.5,0],
       [0,.5,0],
       [sqrt(3)/2.,0,0],
       [-sqrt(3)/2.,0,0]])

sq_coords = np.array([
       [-.5,.5,0],
       [-.5,-.5,0],
       [.5,.5,0],
       [.5,-.5,0]])

tetra_coords = np.array([
       [.5/sqrt(3),-.5,-(1/4.0)*sqrt(2/3.0)],
       [.5/sqrt(3),.5,-(1/4.0)*sqrt(2/3.0)],
       [-1/sqrt(3),0,-(1/4.0)*sqrt(2/3.0)],
       [ 0,0,(3/4.0)*sqrt(2/3.0)]])

trap_coords = np.array([
       [-1,sqrt(3)/5.,0],
       [0,sqrt(3)/5.,0],
       [1,sqrt(3)/5.,0],
       [-.5,-3*sqrt(3)/10.,0],
       [.5,-3*sqrt(3)/10.,0]])

bipyramid_coords = np.array([
       [.5/sqrt(3),-.5,0],
       [.5/sqrt(3),.5,0],
       [-1/sqrt(3),0,0],
       [0,0,sqrt(2/3.)],
       [0,0,-sqrt(2/3.)]])

oct_coords = np.array([[ 0.,  0.,  1./sqrt(2)],
       [ 0.,  1./sqrt(2),  0.],
       [ 1./sqrt(2),  0.,  0.],
       [ 0.,  -1./sqrt(2),  0.],
       [ -1./sqrt(2),  0.,  0.],
       [ 0.,  0.,  -1./sqrt(2)]])

pol_coords = np.array([
       [-.5/(sqrt(2)),.5/(sqrt(2)),.5/(sqrt(2))+.19641855032959654],
       [.5/(sqrt(2)),.5/(sqrt(2)),-.5/(sqrt(2))+.19641855032959654],
       [.5/(sqrt(2)),-.5/(sqrt(2)),.5/(sqrt(2))+.19641855032959654],
       [-.5/(sqrt(2)),-.5/(sqrt(2)),-.5/(sqrt(2))+.19641855032959654],
       [5/6.0/sqrt(2),-5/6.0/sqrt(2),-5/6.0/sqrt(2)+.19641855032959654],
       [-5/6.0/sqrt(2), 5/6.0/sqrt(2),-5/6.0/sqrt(2)+.19641855032959654]])

bigTri_coords = np.array([
       [0,4*sqrt(3)/6.,0],
       [-.5,sqrt(3)/6.,0],
       [.5,sqrt(3)/6.,0],
       [-1,-2*sqrt(3)/6.,0],
       [0,-2*sqrt(3)/6.,0],
       [1,-2*sqrt(3)/6,0]])

parl_coords = np.array([
       [-1.25,sqrt(3)/4.,0],
       [-.25,sqrt(3)/4.,0],
       [.75,sqrt(3)/4.,0],
       [-.75,-sqrt(3)/4.,0],
       [.25,-sqrt(3)/4.,0],
       [1.25,-sqrt(3)/4.,0]])

che_coords = np.array([
       [sqrt(3)/2.,2/3.,0],
       [-sqrt(3)/2.,2/3.,0],
       [0,-5/6.,0],
       [0,1/6.,0],
       [sqrt(3)/2.,-1/3.,0],
       [-sqrt(3)/2.,-1/3.,0]])

Sunday, April 20, 2014

First speed test results on my laptop's NVIDIA gpu!

I bought one of the rare laptops with a discrete graphics card (ASUS Zenbook UX32VD) last summer with hopes of running PyCUDA code on it to speed up my scientific computations. I have run computations on a GPU grid in the past, but I have lots of reasons for wanting to run my code locally.

Here is the progress I've made:
-installed Bumblee
-installed NVIDIA drivers (64-bit)

The first test I ran to make sure the installation was good at this point was:

cd /opt/VirtualGL/bin
optirun ./glxspheres

output:
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: GeForce GT 620M/PCIe/SSE2
78.883064 frames/sec - 88.033499 Mpixels/sec
78.467656 frames/sec - 87.569904 Mpixels/sec
80.333654 frames/sec - 89.652358 Mpixels/sec
80.144371 frames/sec - 89.441118 Mpixels/sec
78.961290 frames/sec - 88.120799 Mpixels/sec

Compared to the speeds for running it without optirun:
./glxspheres

output:
Polygons in scene: 62464
Visual ID of window: 0x20
Context is Direct
OpenGL Renderer: Mesa DRI Intel(R) Ivybridge Mobile x86/MMX/SSE2
60.521833 frames/sec - 67.542366 Mpixels/sec
59.924707 frames/sec - 66.875973 Mpixels/sec
60.537515 frames/sec - 67.559867 Mpixels/sec
60.056097 frames/sec - 67.022604 Mpixels/sec
59.947988 frames/sec - 66.901955 Mpixels/sec

Great! Optirun accessed the GPU-- a GeForce GT 620M and used it to run at 80 fps as opposed to the 60 fps given by the intel chip. But, what I really want to do is to run computations on the gpu using PyCUDA. I found some a great sample speed test written with pycuda here: http://wiki.tiker.net/PyCuda/Examples/SimpleSpeedTest.

I started up ipython with optirun ipython --pylab and then ran the script. The smaller the time the better, and the first three values are the results of the repeated numerical computation-- they should all be identical.

output:
Using nbr_values == 8192
Calculating 100000 iterations
SourceModule time and first three results:
0.264477s, [ 0.005477  0.005477  0.005477]
Elementwise time and first three results:
0.349142s, [ 0.005477  0.005477  0.005477]
Elementwise Python looping time and first three results:
2.101326s, [ 0.005477  0.005477  0.005477]
GPUArray time and first three results:
6.302837s, [ 0.005477  0.005477  0.005477]
CPU time and first three results:
4.637617s, [ 0.005477  0.005477  0.005477]

The speedtest compares five different methods of computation. The first four are on the GPU, and the last one is on the CPU. Some of my times are better than the examples given in the comments of the code, and some are worse. It looks like I might be able to expect a factor of 10 speed improvement from using the GPU, but maybe not any more than that. I wish I had someone else's results from their ASUS Zenbook (GPU specs here: http://www.geforce.com/hardware/notebook-gpus/geforce-gt-620m/specifications) to compare to!

Thursday, March 20, 2014

Navigating an Ordered Dictionary

While working with a fit result in python (using this package: https://github.com/lmfit/lmfit-py), I got the following:

In [104]: result.params['a']
Out[104]: <Parameter 'a', value=-0.017319048843571397 +/- 0.00387, bounds=[-inf:inf]>

Where a was one of the parameters that I fit for. I wanted to get the standard error (0.00387) to use in a plot, but I didn't know how!

Here's how to find the dictionary key words:

In [106]: result.params['a'].__dict__
Out[106]:
{'_val': -0.017319048843571397,
 'correl': {'std': 0.00014518047262818826},
 'deps': None,
 'expr': None,
 'from_internal': <function lmfit.parameter.<lambda>>,
 'init_value': 0,
 'max': inf,
 'min': -inf,
 'name': 'a',
 'stderr': 0.0038656946786479111,
 'user_value': 0,
 'vary': True}

So, result.params['a'].stderr returns the value. Simple enough!

Monday, December 30, 2013

running Python scripts on double click

I've been writing some software to interface with a camera. This had to be done on Windows because of the equipment drivers. In the end, I wanted to deliver a product to my research group that was easy to use-- e.g. double click on this icon and a camera gui will come up that allows you to view and save images streaming from the camera.

The secret to getting the double-click to work was to make a shortcut to the master script, put the shortcut on the desktop, then right click and choose "open with", "choose default program." You want to set the default program to pythonw.

If that is not in the list of suggested programs, you will need to browse for it. To avoid browsing, you can go to the start menu and search for pythonw. Then right click on pythonw and choose "open file location." Copy the file location and then use that as the location of the program when you click "Browse..." to associate a program with this type of file.

That's all!

If you ever want to edit the .py file instead of running it with the python interpreter (pythonw), you can right click and open with your favorite text editor. I had to make the shortcut because the actual python file is in a directory with other files it needs to access-- I didn't want to put them ALL on the desktop.

Tuesday, November 19, 2013

drafting with CAD and DraftSight

For my research, I needed to learn how to make CAD drawings as a step towards making some micro-devices. The procedure for making the devices involves ordering a transparency with high-precision, high-detail designs on it. Mine came from http://www.outputcity.com/. This "mask" is used in a photo-polymerization step to make micro-devices with the right ins and outs.

In any case... I needed to learn CAD. Luckily, my friend Don gave me the 1-hour lesson. Here is what I learned:

CAD is a very methodical, logical way way to make precise drawings. BUT, it's entirely different than any other computer drawing software I used. I had to learn the new paradigm. Once I realized how different it is, I learned quickly. Here are my notes.

commands and tips (type, then hit enter or space):
Type commands, and they will appear after the : at the bottom panel of DraftSight. Hit enter or space to run the command.
pan - to grab the workspace and move it around
*or move around drawing by zooming in and out with mouse wheel
trim - to cut off excess bits of lines
copy - to copy features
move - to move features
array - to create a grid replicating a single unit already drawn
offset - to replicate a feature some distance away
fillet - extends to lines to a point where they meet
mirror - create a mirror image of an existing feature (keep or remove original)
rotate  - rotate a feature
zoom - followed by e zooms out to show the full extent of the drawing
can set up reference lines to use to guide real lines, then trim references
right and left drag boxes are different-- to the left selects any object that partially sticks into the area selected. dragging to the right only selects objects entirely within the selected region.
use esc to deselect what you have selected

details for my application:
can't print features less than 7 microns
nothing smaller than 50 to 75 microns is cheaper
wide and flat features are easy, features with a 1x1 aspect ratio are good
the printers are 10,000 dpi and 25,400 dpi, and you want to have 7 dots per feature
in the proof, check for polarity (dark vs. clear) and check for missing features
the edge of the drawing will be clear, crossing the first line coming in from an edge brings you into a dark region
dimensions are in microns
20 micron text is OK, height = 800 is readable by eye
around height = 100 is good for my 90x magnified microscope with 120 micron x 100 micron field of view
save as 2007-2009 .dwg, send a dxf to the printer

Tuesday, October 8, 2013

Fresh Install

I ran into problems with my computer after some updates on Friday and tried to fix them. But, no luck. So, I decided to save everything and then do a fresh install. Having to reinstall after just a couple months of use was annoying... but it did fix my computer! Everything is working again.

I learned that I did not need to flash the bios again-- bios are lower level and don't get modified by the operating system.

The following are what I need to do when I configure a new system for myself:

1) Reenter wireless passwords
2) Install additional software
3) Configure settings and accounts (e.g. sync Dropbox account)
4) Configure Ubuntu settings to my liking
5) Get network resources working

To make all easier next time, I'm saving my .config, .thunderbird, and .mozilla directories as well as making a text document with a list of all the software that I install so that I can just run:

sudo apt-get install `cat packages.txt`

I'm glad to be up and running again.