Terra 0.7: Better Visualization, Compilation, Memorization

Dec 26, 2018 · 5 min read

Written by: Donny Greenberg, with Ali Javadi-Abhari and Matthew Treinish

This week we release Qiskit Terra 0.7, and with it a number of big investments in the transparency, power, and extensibility of the Terra platform. Our release notes are very thorough and are definitely worth a read, but I want to highlight three major changes that I find particularly exciting.

This notebook includes all of the examples below, as well as a detailed in-code rundown of all of Terra 0.7’s new features and breaking changes. I’d also encourage you to take a look at the qiskit-tutorial repo (both the qiskit/ and community directories/), which has been significantly updated for this release.

First, an Important Note on Upgrading

For this release, we highly recommend uninstalling Qiskit (only Terra, not Aqua) and reinstalling, rather than running a pip upgrade. This is because we’ve reorganized the pip installs so the pip install for Terra is pip install qiskit-terra, the pip install for Aer is pip install qiskit-aer, and pip install qiskit installs both. This renaming will likely introduce errors if you upgrade without uninstalling first. Even if you’ve installed from source, we still recommend doing this.


Robust circuit and result visualizations are make-or-break for quantum software developer velocity. They are indispensable for rapid prototyping, collaboration, and troubleshooting. We’ve reviewed our visualization tools and updated them with a focus on stability and extensibility.

Some highlights:

  • Matplotlib has been removed as a dependency from Terra because some users have trouble installing it. The Matplotlib-based tools can still be installed via pip install qiskit[visualization]
  • The circuit visualization functions have been turned into separate objects for cleanliness and extensibility. circuit.draw() has been added as a convenience function, and a no-fuss ASCII output mode has been added.

Fig 1: ASCII art == CS steampunk

But matplotlib and latex drawing are fully-featured and better than ever:

Fig 2: What a luxuriously subtle blue background

Fig 3: \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw

  • There’s a new DAGCircuit visualizer too (Note: this requires a few additional libraries not in core Terra requirements):

Fig 4: Happy Hanukkah


The transpiler is the workhorse of Terra. It’s how we keep circuits backend agnostic and compilable for arbitrary quantum hardware. The transpiler in Terra 0.6 was not transparent or extensible enough for increasingly sophisticated transpilation methods, so we tore it down and rewrote it to be much more robust.

Some highlights:

  • The transpiler now transpiles circuits into circuits, rather than into DAGCircuits. This is much more transparent, and allows the end user to view and understand what individual transpiler passes are doing to their circuit. This is best explained by example:

Here’s a sort of messy circuit that won’t fit nicely on our hardware as is:

The most naive thing we can do is simply move qubits around greedily with swaps. Let’s see how the BasicSwap pass does here:

Not great. Let’s try Sven Jandura’s LookaheadSwap, submitted for the 2018 Qiskit Developer Challenge. Sven’s swap pass was merged into Terra, and we will have two more passes from other winners of the Qiskit Developer Challenge soon! We’re constructing a diverse set of passes, many user contributed, to meet the wide-ranging needs and mapping scenarios of circuits in the wild.

Better! One more try with the StochasticSwap:

Even better, but still more room to go. Right now this all happens behind the scenes for many users, but we hope that these tools make digging into transpilation much more accessible to those attempting to squeeze as much performance as possible out of their experiments on hardware.

  • The PassManager is also much more straightforward and extensible. See the new “Writing a Transpiler Pass” blog post coming soon.

Backends and Shot Memory

We’ve updated our backend connectors to work through clear and more consistent APIs, and added a new shot memory feature across all of our backends. The backends now return a result object which is interacted with through methods rather than direct access to data. We’ve also split our simulator suite into three:

  • Aer — This is our fully-featured high performance simulator suite, located in a separate repo, here.
  • BasicAer — This is a limited-functionality version of Aer packaged inside of Terra for convenience.
  • LegacySimulators — These are the older simulators from Terra 0.6-.

Shot memory is a complete log of shot results when you run on Quantum hardware or shot-based simulators. This is critical for characterization and analysis of hardware behavior, and a frequently requested feature.

Fig 5: Now you can put Big Data on your Linkedin

Looking forward

I like to describe the present state of Terra as C in the early days of Unix: its core competency is compilation for arbitrary hardware and managing interaction with the processing unit. This update was a big one in that regard. The infrastructure focus is an investment in our future, and next quarter’s work in particular. Better visualizations means users can construct more complex quantum programs, and better transpilation means that we have a better shot of running those circuits well on hardware. Now that we’ve laid a strong infrastructural foundation, we’re turning to our core user journeys and focusing on delivering abstractive and syntactic power to scientists and developers alike.

You can expect updates to circuit construction, registers, gates, and operators in the near future. Please do not hesitate to reach out through slack with ideas and feedback!


A community to discuss Qiskit, programming quantum computers, and anything else related to quantum computing.


Written by


An open source quantum computing framework for writing quantum experiments and applications



A community to discuss Qiskit, programming quantum computers, and anything else related to quantum computing.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade