An Introduction to Quantum Computing with Open Source Cirq Framework

As the title suggests what we are about to begin discussing, this article is an effort to understand how far we have come in Quantum Computing and where we are headed in the field in order to accelerate scientific and technological research, through an Open Source perspective with Cirq.

First, we will introduce you to the world of Quantum Computing. We will try our best to explain the basic idea behind the same before we look into how Cirq would be playing a significant role in the future of Quantum Computing. Cirq, as you might have heard of recently, has been breaking news in the field and in this Open Science article, we will try to find out why.

Before we start with what Quantum Computing is, it is essential to get to know about the term Quantum, that is, a subatomic particle referring to the smallest known entity. The word Quantum is based on the Latin word Quantus, meaning, “how little”, as described in this short video:

It will be easier for us to understand Quantum Computing by comparing it first to Classical Computing. Classical Computing refers to how today’s conventional computers are designed to work. The device with which you are reading this article right now, can also be referred to as a Classical Computing Device.

Classical Computing

Classical Computing is just another way to describe how a conventional computer works. They work via a binary system, i.e, information is stored using either 1 or 0. Our Classical computers cannot understand any other form.

In literal terms inside the computer, a transistor can be either on (1) or off (0). Whatever information we provide input to, is translated into 0s and 1s, so that the computer can understand and store that information. Everything is represented only with the help of a combination of 0s and 1s.

Quantum Computing

Quantum Computing, on the other hand, does not follow an “on or off” model like Classical Computing. Instead, it can simultaneously handle multiple states of information with help of two phenomena called superimposition and entanglement, thus accelerating computing at a much faster rate and also facilitating greater productivity in information storage.

Please note that superposition and entanglement are not the same phenomena.

So, if we have bits in Classical Computing, then in the case of Quantum Computing, we would have qubits (or Quantum bits) instead. To know more about the vast difference between the two, check this page from where the above pic was obtained for explanation.

Quantum Computers are not going to replace our Classical Computers. But, there are certain humongous tasks that our Classical Computers will never be able to accomplish and that is when Quantum Computers would prove extremely resourceful. The following video describes the same in detail while also describing how Quantum Computers work:

A comprehensive video on the progress in Quantum Computing so far:

Noisy Intermediate Scale Quantum

According to the very recently updated research paper (31st July 2018), the term “Noisy” refers to inaccuracy because of producing an incorrect value caused by imperfect control over qubits. This inaccuracy is why there will be serious limitations on what Quantum devices can achieve in the near term.

“Intermediate Scale” refers to the size of Quantum Computers which will be available in the next few years, where the number of qubits can range from 50 to a few hundred. 50 qubits is a significant milestone because that’s beyond what can be simulated by brute force using the most powerful existing digital supercomputers. Read more in the paper here.

With the advent of Cirq, a lot is about to change.

What is Cirq?

Cirq is a python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits that we just talked about. In other words, Cirq can address challenges to improve accuracy and reduce noise in Quantum Computing.

Cirq does not necessarily require an actual Quantum Computer for execution. Cirq can also use a simulator-like interface to perform Quantum circuit simulations.

Cirq is gradually grabbing a lot of pace, with one of its first users being Zapata, formed last year by a group of scientists from Harvard University focused on Quantum Computing.

Getting started with Cirq on Linux

The developers of the Open Source Cirq library recommend the installation in a virtual python environment like virtualenv. The developers’ installation guide for Linux can be found here.

However, we successfully installed and tested Cirq directly for Python3 on an Ubuntu 16.04 system via the following steps:

Installing Cirq on Ubuntu

Cirq Framework for Quantum Computing in Linux

First, we would require pip or pip3 to install Cirq. Pip is a tool recommended for installing and managing Python packages.

For Python 3.x versions, Pip can be installed with:

sudo apt-get install python3-pip

Python3 packages can be installed via:

pip3 install <package-name>

We went ahead and installed the Cirq library with Pip3 for Python3:

pip3 install cirq

Enabling Plot and PDF generation (optional)

Optional system dependencies not install-able with pip can be installed with:

sudo apt-get install python3-tk texlive-latex-base latexmk
  • python3-tk is Python’s own graphic library which enables plotting functionality.
  • texlive-latex-base and latexmk enable PDF writing functionality.

Later, we successfully tested Cirq with the following command and code:

python3 -c 'import cirq; print(cirq.google.Foxtail)'

We got the resulting output as:

Configuring Pycharm IDE for Cirq

We also configured a Python IDE PyCharm on Ubuntu to test the same results:

Since we installed Cirq for Python3 on our Linux system, we set the path to the project interpreter in the IDE settings to be:


In the output above, you can note that the path to the project interpreter that we just set, is shown along with the path to the test program file (test.py). An exit code of 0 shows that the program has finished executing successfully without errors.

So, that’s a ready-to-use IDE environment where you can import the Cirq library to start programming with Python and simulate Quantum circuits.

Get started with Cirq

A good place to start are the examples that have been made available on Cirq’s Github page.

The developers have included this tutorial on GitHub to get started with learning Cirq. If you are serious about learning Quantum Computing, they recommend an excellent book called “Quantum Computation and Quantum Information” by Nielsen and Chuang.


OpenFermion is an open source library for obtaining and manipulating representations of fermionic systems (including Quantum Chemistry) for simulation on Quantum Computers. Fermionic systems are related to the generation of fermions, which according to particle physics, follow Fermi-Dirac statistics.

OpenFermion has been hailed as a great practice tool for chemists and researchers involved with Quantum Chemistry. The main focus of Quantum Chemistry is the application of Quantum Mechanics in physical models and experiments of chemical systems. Quantum Chemistry is also referred to as Molecular Quantum Mechanics.

The advent of Cirq has now made it possible for OpenFermion to extend its functionality by providing routines and tools for using Cirq to compile and compose circuits for Quantum simulation algorithms.

Google Bristlecone

On March 5, 2018, Google presented Bristlecone, their new Quantum processor, at the annual American Physical Society meeting in Los Angeles. The gate-based superconducting system provides a test platform for research into system error rates and scalability of Google’s qubit technology, along-with applications in Quantum simulation, optimization, and machine learning.

In the near future, Google wants to make its 72 qubit Bristlecone Quantum processor cloud accessible. Bristlecone will gradually become quite capable to perform a task that a Classical Supercomputer would not be able to complete in a reasonable amount of time.

Cirq would make it easier for researchers to directly write programs for Bristlecone on the cloud, serving as a very convenient interface for real-time Quantum programming and testing.

Cirq will allow us to:

  • Fine tune control over Quantum circuits,
  • Specify gate behavior using native gates,
  • Place gates appropriately on the device &
  • Schedule the timing of these gates.

The Open Science Perspective on Cirq

As we all know Cirq is Open Source on GitHub, its addition to the Open Source Scientific Communities, especially those which are focused on Quantum Research, can now efficiently collaborate to solve the current challenges in Quantum Computing today by developing new ways to reduce error rates and improve accuracy in the existing Quantum models.

Had Cirq not followed an Open Source model, things would have definitely been a lot more challenging. A great initiative would have been missed out and we would not have been one step closer in the field of Quantum Computing.


To summarize in the end, we first introduced you to the concept of Quantum Computing by comparing it to existing Classical Computing techniques followed by a very important video on recent developmental updates in Quantum Computing since last year. We then briefly discussed Noisy Intermediate Scale Quantum, which is what Cirq is specifically built for.

We saw how we can install and test Cirq on an Ubuntu system. We also tested the installation for usability on an IDE environment with some resources to get started to learn the concept.

Finally, we also saw two examples of how Cirq would be an essential advantage in the development of research in Quantum Computing, namely OpenFermion and Bristlecone. We concluded the discussion by highlighting some thoughts on Cirq with an Open Science Perspective.

We hope we were able to introduce you to Quantum Computing with Cirq in an easy to understand manner. If you have any feedback related to the same, please let us know in the comments section. Thank you for reading and we look forward to see you in our next Open Science article.

Similar Posts

  • imho :

    it’s just madness. nobody – not even in our time – _understands_ quantum physics (especially not in connection with gravitation ; _constructed_ “anti-de sitter space” or not) . entanglement, non-locality, wave function collapse, et cetera. what’s going on here? yes, “it works” (that way). and we’ve got the mathematics for it, thanks to complex numbers. that’s all physicists “know”. but they do not “understand” quantum physics. nobody does. this hasn’ changed since “the beginning” in the last century.

    and now the sceptre is also handed over to socially questionable “geeks” resp. programmers resp. computer scientists who know even less than a physicist. and that is not enough – demonstrably malicious companys like google, microsoft, ibm & co. including governments around the world are quite coveted on this “new” technology. of course, because it gives them .. “power” (not only in the area of cryptography, so called “a.i.”, so called “maschine learning”, mass surveillance, modern warfare, et cetera). more important than ever before :


    stick to it once and for all. thx. also @ubuntu & _everybody_ else.

    + just as important for “enthusiasts” (personal & universal logical/mathematical limits :


    as long as “technological progress” is faster than “social progress” (which is even declining _because_ of “our” so called technological “progress”), you people have to stop all this nonsense. doing everything possible – because it is possible? nope. most scientists have learned that lesson in the meantime. computer – “scientists” .. unfortunately never.

    kurt gödel turns in his grave. george spencer brown too:


    you people have to understand what’s going on. and that’s inseparable from ethics (too). then you can move on. but i know, that’s never gonna happen.

  • I would have loved to see a different explanation of how quantum computing differs from classic computing:
    1. Computing is about decision making, a 1 standing for, say, turn left, is right, carry on . . . and a 0 meaning the opposite: turn right, is false, halt the procedure . . .
    2. Classical computing uses spoken human language as its paradigm. In human speech, words are uttered one after the other, in a classical computer, each decision is made one after the other.
    3. Quantum computing uses a book (if it is a small computer) or a library as a paradigm.
    3.1 Take a question: find all people dumb enough to spell the word WRONG as ROOOONG. If you restrict the problem further to a book of 1000 pages, you might tackle the question by reading the book from cover to cover. That is classical computing. Or you might tackle it by assigning 1000 programmers to read one page each. That is still classical computing, but it is faster than the previous one, because it is done in parallel.
    Answering the question remains in the realm of classical computing because words are read one letter at a time.
    3.2 Now change the construction of the book. Instead of funny thingies called letters and words arranged on sheets of paper stacked on top of each other arranged on library shelves, you have a gadget with a button that sounds a word if pressed, and that switches on a light if you shout a word at it. Call the gadget a (set of) qubit(s) and the button a quantum computer, and you know what encoding information in a qubit is all about. Press the button again, and again, and again, and you hear the book being read to you, one word at a time, one book at a time, moving from one library shelf to the next as needed. That is still classical computing.
    3.3 All the information is contained within that one gadget. That is the gist of what is meant by superposition, and what is meant by “is in the book”, “is available from the library”. Now, the equivalent to entanglement is the index of the book/library. To access it, you have to go elsewhere, running the risk that a page falls out of the book / the book gets mislaid after its index was read. In that case, entanglement is broken, and the index is no longer valid or useful.
    Now, assuming after such a long explanation, entanglement is still ok, shout the word ROOOONG at your quantum computer, if there is an incidence of “ROOOONG” , the light will switch on, and the respective page will open for you, all in a single step. That is quantum computing, transposed onto an ordinary book/library example.
    It’s quick, provided that entanglement works. And that is the rub: provided entanglement works. Since temperature is the major fiend for entanglement, it is no surprise that quantum computing works only near absolute zero temperatures

    • Since our main focus was on how Cirq’s Open Source model impacts the future of Quantum Computing, we had to keep the introduction brief. But yours is a great way of bridging that void and comparing the two! Your comment now actually adds more value to this topic! So, thank you so much for your deeply illustrative and elaborate insight!