Monday, October 29, 2007

Flickr upload

I had not used Flickr in 18 months and when I wanted to use it today my script didn't work anymore since they have changed their API significantly in the meantime. Simply updating the perl module was not enough and I found the documentation the the web to be rather cryptic. Thus as a service to the community, this is what finally worked for me:

#!/usr/bin/perl

use Flickr::API;
use Flickr::Upload;

# Path to pictures to be uploaded
my $flickrdir = '/home/robert/fotos/flickr';

my $flickr_key = 'PUT YOUR KEY HERE';
my $flickr_secret = 'PUT YOUR SECRET HERE';


my $ua = Flickr::Upload->new( {'key' => $flickr_key, 'secret' => $flickr_secret} );
$ua->agent( "perl upload" );


my $frob = getFrob( $ua );
my $url = $ua->request_auth_url('write', $frob);
print "1. Enter the following URL into your browser\n\n",
"$url\n\n",
"2. Follow the instructions on the web page\n",
"3. Hit when finished.\n\n";

<>;
my $auth_token = getToken( $ua, $frob );
die "Failed to get authentication token!" unless defined $auth_token;

print "Token is $auth_token\n";


opendir(FLICKR, $flickrdir) || die "Cannot open flickr directory $flickrdir: $!";
while(my $fn = readdir FLICKR){
next unless $fn =~ /[^\.]/;
print "$flickrdir/$fn\n";

$ua->upload(
'auth_token' => $auth_token,
'photo' => "$flickrdir/$fn",
'is_family' => 1
) or print "Failed to upload $fn!\n";

}




sub getFrob {
my $ua = shift;

my $res = $ua->execute_method("flickr.auth.getFrob");
return undef unless defined $res and $res->{success};

# FIXME: error checking, please. At least look for the node named 'frob'.
return $res->{tree}->{children}->[1]->{children}->[0]->{content};
}

sub getToken {
my $ua = shift;
my $frob = shift;

my $res = $ua->execute_method("flickr.auth.getToken",
{ 'frob' => $frob ,
'perms' => 'write'} );
return undef unless defined $res and $res->{success};

# FIXME: error checking, please.
return $res->{tree}->{children}->[1]->{children}->[1]->{children}->[0]->{content};
}

You need a key and a secret which you can generate here. Of course, you also need the module

perl -MCPAN -e shell
install Flickr::Upload

Then all you have to do is to copy (or link) all pictures to be uploaded to one directory (/home/robert/fotos/flickr in my case) and run the script. It gives you an URL you have to paste into your browser and then press ok and the upload begins.

Friday, October 26, 2007

Quantum Field lectures and some notes

The past few weeks here were quite busy as now the semester has started (October 15th) and with it the master program "Theoretical and Mathematical Physics" has become reality with the first seven student (one of them attracted apparently via this blog) have arrived and are now taking classes in mathematical quantum mechanics, differential geometry, string theory, quantum electrodynamics, conformal field theory, general relativity, condensed matter theory and topology (obviously not everybody attends all these courses).

I have already fulfilled my teaching obligation by teaching a block course "Introduction to Quantum Field Theory" the two weeks before the semester. Even though we had classes both in the morning and the afternoon for two weeks there was obviously only a limited amount of time and I had to decide which small part of QFT I was going to present. I came up with the following

  • Leave out the canonical formalism completely. Many courses start with it as this was the historical development and students will recognize commutation relations from quantum mechanics classes. But the practical use of it is limited: As soon as you get to interacting theories it becomes complicated and the formalism is just horrible as soon as you have gauge invariance. Of course, it's still possible to use it (and it is the formalism of choice for some investigations) but it's definitely not the simplest choice to be presented in an introductory class.
  • Thus, I was going to use the path integral formalism from day one. I spend the first two days introducing it via a series of double (multi) slit (thought) experiments motivating that a sum over paths is natural in quantum mechanics and then arguing for the measure factor by demanding the correct classical limit in a saddle point approximation. This heuristic guess for the time evolution was then shown to obey Schrödinger's equation and thus equivalence with the usual treatment was established at least for systems with a finite number of degrees of freedom.
  • In addition, proceeding using analogies with quantum mechanics can lead to some confusion (at least it did for me when I first learned the subject): The Klein-Gordon equation is often presented as the relativistic version of Schrödinger's equation (after discarding an equation involving a square root because of non-locality). Later then it turns out, the field it describes is not a wave function as it cannot have a probability interpretation. The instructor will hope that this interpretation is soon to be forgotten because it's really strange to think of the vector potential as the wave function of the photon which would be natural from this perspective. And if the Klein-Gordon field is some sort of wave function, why does it again need to be quantised? So what kind of objects are the field operators and what do they act on? In analogy with first quantisation one would guess they act on wave functionals that map field configurations on a Cauchy surface to complex numbers which are in some functional integral sense square integrable. OK, Fock space does the job but again, that's not obvious.
  • All these complications are avoided using path integrals. At least if one gets his head around these weird infinite dimensional integrals and the fact that in between we have to absorb infinite normalisation constants. But then, only a little bit later, one arrives at Feynman rules and for example the partition function for the free field is a nice simple expressions and all strange integrals are gone (they have been performed in a Gaussian way).
  • So instead of requantising an already (pseudo) quantum theory, I introduced the Klein-Gordon equation just as any classical equation of motion of a system which happens to have a continuum of degrees of freedom (I did it via the continuum limit of some "balls with springs" model). Thus before getting into any fancy quantum business, we solved this field equation (including the phi^4 interaction) classically. Doing that perturbatively, we came up with Feynman rules (tree diagrams only of course) and a particle-wave duality while still being entirely classical. As I am not aware of a book which covers Feynman diagrams from a classical perspective I have written up some lecture notes of this part. They also include the discussion of kink solutions which were an exercise in the course and which suggest the limitations of the perturbative approach and how solitonic objects have to be added by hand. (To be honest, advertising these lecture notes is the true purpose of this post... Please let me know you comments and corrections!)
  • The other cut I decided to make was to restrict attention only to the scalar field. I did not discuss spinors or gauge fields. They are interesting subjects for themselves but I decided to focus on features of quantum field theories rather than representation theory of the Lorentz group. The Dirac equation is a nice subject by itself and discussing gauge invariance leading to a kinetic operator which is not invertible (and thus requiring a gauge fixing and eventually ghosts to make it invertible) would have been nice, but there was no time. But as I said, there is a regular course on QED this semester and there all these things will be covered.
  • These severe cuts allowed us to get quite deep into the subject: When I took a QFT course, we spend the entire first semester discussing only free fields (spin 0, 1/2 and 1). Here, in this course, we managed to get to interacting fields in only two weeks including the computation of 1 loop diagrams. We computed the self-energy correction and the fish graph (including Schwinger parameters, Feynman trick and all that) went through their dimensional regularisation and renormalisation (including a derivation of the important residues of the gamma function). The last lecture, I could even sketch the idea of the renormalisation group, running coupling constants and why nature seems to use only renormalisable theories for particle physics (as the others have vanishingly small couplings at our scales).
This was quite an ambitious program but I think it went quite well (and the exam shows that I managed to transmit at least some information).

As far as books are concerned: For the preparation, I used Ryder, my favorite QFT text for large parts (and Schulman's book for the path integrals in quantum mechanics introduction). Only later I discovered that Zinn-Justin's book has a very similar approach (at least if you ignore all material on fields other than spin 0 and all the discussions of critical phenomena). Only yesterday, a copy of the new QFT book by Srednicki arrived on my desk (thanks CUP!) and from what I read there so far, this looks also extremely promising!

For your entertainment, I have also uploaded the exercise sheets here:
1 2 3 4 5

PS: If instead of learning QFT in two weeks you want to learn string theory in two minutes check this out.Didn't know molecules were held togehter by the strong force, though...