unitaryfund / mitiq

Mitiq is an open source toolkit for implementing error mitigation techniques on most current intermediate-scale quantum computers.
https://mitiq.readthedocs.io
GNU General Public License v3.0
358 stars 157 forks source link

Better check for fold-ability / support for parameterized circuits #911

Closed rmlarose closed 2 years ago

rmlarose commented 3 years ago

Right now we say that if a circuit doesn't have a unitary, it has non-unitary gates which are not terminal measurements and therefore cannot be folded.

https://github.com/unitaryfund/mitiq/blob/31f10c252b7015a7415e450c9347f19d5b9fe400/mitiq/zne/scaling/folding.py#L69-L73

A Cirq circuit with symbols doesn't have a unitary but does have an inverse:

import sympy
import cirq

theta = sympy.Symbol("theta")
q = cirq.LineQubit(0)
ansatz = cirq.Circuit(cirq.ry(theta).on(q))
print(ansatz)  # 0: ───Ry(theta)───

cirq.has_unitary(ansatz)  # False
cirq.inverse(ansatz)  # 0: ───Ry(-theta)───

So a better check is looking for an inverse rather than looking for a unitary.

Current behavior

zne.scaling.fold_*(ansatz) raises UnfoldableCircuitError.

Desired behavior

Ability to fold parameterized circuits. For the above circuit, zne.scaling.fold_*(ansatz, scale_factor=3) should return 0: ───Ry(theta)───Ry(-theta)───Ry(theta)───.

purva-thakre commented 3 years ago

@rmlarose I can take this.

andreamari commented 3 years ago

It would be good (but probably not easy) to also support this for other frontends beyond Cirq.

rmlarose commented 3 years ago

You got it - thanks Purva!

purva-thakre commented 2 years ago

It would be good (but probably not easy) to also support this for other frontends beyond Cirq.

@andreamari Would you prefer these be added to each non_cirq_utils available in this folder ?

andreamari commented 2 years ago

@purva-thakre I think we can start with supporting parametrized Cirq circuits as suggested by @rmlarose in this issue. This is already a useful improvement.

In a second step we can think how to support non-Cirq parametrized circuits. This second step would require to define conversion rules for parametrized gates to and from Cirq.

purva-thakre commented 2 years ago

In a second step we can think how to support non-Cirq parametrized circuits. This second step would require to define conversion rules for parametrized gates to and from Cirq.

@andreamari That's what I thought was needed for the other frontends. I started to figure out how it would work for Qiskit parametrized circuits yesterday.

I'll create a separate PR for each as I work on them and link to this issue. Or if you would prefer to create separate issues to keep better track of these, feel free to assign them to me.