Why I Switched to Julia

The following story explains why I began programming in Julia. Since then, I have found that Julia improves the performance of my other econometric estimators. However, Julia has a major disadvantage in that it lacks informative documentation and tutorials, much less accumulated discussion on sites like stackoverflow. This blog is meant to record the skills I am learning in Julia over time, to serve as a tutorial for economists and others learning the Julia programming language.

Is Julia the Future of Computational Economics?

I am currently estimating a structural econometric model of game-theoretic parent-child interaction. Using the standard implementation of Python (the code is written entirely in NumPy and SciPy with data prepared by Pandas), the optimizer ran for 24 hours, then terminated due to the 5,000 iteration limit. It was converging smoothly, but never quite arrived. While waiting for the estimates last night (and growing increasingly impatient), I installed Julia and its packages, learned how to program in Julia, rewrote the estimation in Julia, and this morning successfully optimized the likelihood in Julia.

The contrast is staggering: the optimization that didn’t converge after 24 hours in Python converged after only 15 minutes in Julia while Python was still running on the same processor. Julia was already achieving a greater likelihood than Python after only 5 minutes even though Python had a 20-hour head start. They are both using the same optimization algorithm (including numerical tolerance), and the structure of the code is identical. Julia evaluates the likelihood in 0.5 seconds, while Python requires 21 seconds per evaluation, so Julia is about 40 times faster in the function evaluation, and about 100 times faster in the optimizer (I’m giving Python the benefit of the doubt even though it never converged).

The final iteration of Python was approaching the Julia optimal likelihood and getting closer; the only difference was that Julia arrived much, much more quickly. Since my next step is to bootstrap the estimator, speed is extremely important. Some practical arithmetic: on my four-core laptop, it would take two-thirds of a year to bootstrap this estimator 1,000 times, whereas Julia could do it in fewer than three days (though I’m planning to run the bootstrap in batch on the server).

I am agnostic on programming languages; I use whatever gets the answer fastest and can be reproduced most clearly, and I often use multiple languages on the same project to get the best features of each. My only claim is that Julia has taken the Python code, with minimal syntax changes, and executed the code 100 times faster for someone who had no prior experience with Julia. This was not a contrived, time-testing code; this is the estimator motivated by economic theory. The 100-fold speed increase of Julia relative to Python has been found elsewhere in computational economics.

So, is Julia the programming language of the future in structural econometrics? I’m not sure, but it seems to dominate Python and R at the moment.

Bradley J. Setzler


    1. HI,

      Thanks for your comment. As I show in the simple example above (REVISITED: Julia vs. Python Speed Comparison: Bootstrapping the OLS MLE), which includes the short, clean codes for reproducibility, Julia is at least 5-times faster than Python when there are very few operations. Now, just imagine putting many more algebraic operations inside of the objective function. It’s very easy to reach a case where Julia runs 100-times faster than Python, and it arises especially in real-world applications of economics, where the objective function tends to be highly complex.

      But don’t take my word for it — I have posted links to the paper and corresponding repository by Aruoba and Fernandez-Villaverde, which has undergone many rounds of public profiling and still finds the 100-fold speed increase of Julia relative to Python, for a real-world problem.

      All the best,

  1. Hi Bradley,
    thanks a lot for putting this site up and sharing your experience with Julia. I am planning to write a PhD on a labor/education topic myself, using strucutral estimation with DCDP. Since you mentioned your computer/CPU in one post, and I am about to buy a new one soon, I was wondering what you would recommend hardware-wise, i.e. in terms of RAM and CPU. Do you think an i7 quad core is highly recommendable, or might something with less power still do it? I know this is question is not about Julia, but it seems somehow related, and you seem to be the right person to ask. Thanks in advance, John (from Germany).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s