Optimizing quantum circuit using boolean algebra

Since the latest v0.1.18 version, the Qlasskit library offers two useful tool for circuit analysis and optimization.

  • Decompiler: given a quantum circuit is able to detect section that can be represented as boolean expressions

  • circuit_boolean_optimizer: a pipeline that given a quantum circuit, decompose it in boolean expressions form and optimize it using boolean algebra

Let’s have a look on how to use these features. We first create the following quantum circuit:

Now, using the decompile function we can detect “classical parts” and decode them as boolean expression; this is the result for the previous quantum circuit.

dc = Decompiler().decompile(qcircuit)
		(0, 7)
		(X, [2], None), (CCX, [0, 2, 3], None), (CCX, [1, 3, 4], None), (CX, [4, 5], None), (CCX, [1, 3, 4], None), (CCX, [0, 2, 3], None), (X, [2], None)
		(q5, q4 ^ q5 ^ (q1 & (q3 ^ (q0 & ~q2))))

Reading the resulting boolean expression (q5, q4 ^ q5 ^ (q1 & (q3 ^ (q0 & ~q2)))), and knowing that q0 and q1 are inputs, while the other qubits are used as ancilla and output qubits, it is clear that the circuit can be optimized.

qc = circuit_boolean_optimizer(qf.circuit(), preserve=[0, 1])

The circuit_boolean_optimizer allows us to perform boolean optimizations in a quantum circuit; from the previous unoptimized example, we then get the following optimized circuit:

Useful Links:

The Python notebook for this blog post is available here:


The Time I Built a Probabilistic Computer

5 minute read

In early 2023, I embarked on a journey to explore the field of probabilistic computing. This endeavor culminated in the construction of a hardware prototype,...

Back to Top ↑


Expanding the Commodore 64 Quantum Emulator

1 minute read

In a recent article I wrote, “Quantum Computing on a Commodore 64 in 200 Lines of BASIC”, published both on Medium and Hackaday.com, shows a two-qubit quantu...

Back to Top ↑


OCaml and Quantum Computing

1 minute read

Qiskit is a python SDK developed by IBM and allows everyone to create quantum circuits, simulate them locally and also run the quantum circuit on a real quan...

Yallo, a new Tezos language

2 minute read

As someone noticed from the previous post, last weeks I started to write a new programming language for Tezos smart contracts. This project was initially int...

King of Tezos: a smart-ponzi on Tezos

2 minute read

While writing a new programming language, it is often useful to write some real use-cases to test the syntax, the language expressiveness and the code cleann...

Favorite dev quote

less than 1 minute read

Documentation is like sex: when it is good, it is very, very good; and when it is bad, it is better than nothing

New blog

less than 1 minute read

This is my new blog, based on jekyll. I’ll soon import old posts from my old blog.

Back to Top ↑


Contractvm: decentralized applications on Bitcoin

less than 1 minute read

Contractvm is a general-purpose decentralized framework based on blockchain. The framework allows to implement arbitrary decentralized applications in an eas...

Back to Top ↑


Dices provably fair - Nonce overflow vulnerability

less than 1 minute read

Most of bitcoin dice software use a system to prove the fair play of the server for each bet. Most of them implement this mechanism using two seed (server se...

Back to Top ↑


Apache2: redirect different domains to subfolder

less than 1 minute read

In the aim to merge two of my server on digitalocean, today I tried to write a mod_rewrite rule to redirect a secondary domain to a subfolder. After one hour...

Back to Top ↑


MineML: F# miner

less than 1 minute read

MineML is a multithread CPU based bitcoin miner written in F#. At the moment it’s a slow implementation, but the class structure offers the possibility to im...

Back to Top ↑