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

mitiq can't support pennylane. #990

Closed sassan72 closed 2 years ago

sassan72 commented 2 years ago

mitiq.interface.conversions.UnsupportedCircuitError: Circuit from module pennylane.tape.tape is not supported.

github-actions[bot] commented 2 years ago

Hello @sassan72, thank you for your interest in Mitiq! If this is a bug report, please provide screenshots and/or minimum viable code to reproduce your issue, so we can do our best to help get it fixed. If you have any questions in the meantime, you can also ask us on the Unitary Fund Discord.

sassan72 commented 2 years ago

import numpy as np

import pennylane as qml from mitiq import zne

with qml.tape.QuantumTape() as tape: qml.RX(np.pi / 2, wires=[0]) qml.CNOT(wires=[0, 1]) qml.expval(qml.PauliZ(wires=[0])) qml.expval(qml.PauliZ(wires=[1]))

print(tape.draw())

scaled_tape = zne.scaling.fold_all(tape, scale_factor=3) print(scaled_tape.draw())

andreamari commented 2 years ago

Hi @sassan72, I am not sure what is the problem, but I have some suggestions. Mitiq currently supports only tapes without measurements. Do you still get an error if you remove these lines:

# qml.expval(qml.PauliZ(wires=[0]))
# qml.expval(qml.PauliZ(wires=[1]))

If you still get an error, could you try to pip install qiskit==0.25 and try again?

sassan72 commented 2 years ago

the code has been written with pennylane not qiskit.

nathanshammah commented 2 years ago

@sassan72 the last comment by @andreamari is to check if there is an issue propagating due to dependency requirement conflicts. We appreciate and look forward for community feedback, but it takes time to debug code. If you want assistance, as we would like to provide it, please answer politely the questions made. The issue is incomplete with respect to the guidelines present in the Mitiq issue's template. Adding a code snippet and a printout from mitiq.about() may be ok in this case.

sassan72 commented 2 years ago

i realized that you had some progress to integrate the Pennylane with Mitiq. Since i have been working with the Pennylane, i was interested in error mitigation with the pennylane+Mitiq.

sassan72 commented 2 years ago

i have download the above code from here: https://github.com/unitaryfund/mitiq/pull/836. i was so curios to run the code which has been written based on Pennylane in the above link: https://github.com/unitaryfund/mitiq/pull/836. But after running, i encountered this error that 'mitiq can't support pennylane'.

here is the code:

import numpy as np

import pennylane as qml from mitiq import zne

with qml.tape.QuantumTape() as tape: qml.RX(np.pi / 2, wires=[0]) qml.CNOT(wires=[0, 1]) qml.expval(qml.PauliZ(wires=[0])) qml.expval(qml.PauliZ(wires=[1]))

print(tape.draw())

scaled_tape = zne.scaling.fold_all(tape, scale_factor=3) print(scaled_tape.draw())

andreamari commented 2 years ago

Hi @sassan72, from the error that you mention it seems that you are using a stable version of Mitiq (maybe 0.10.0). Pennylane support is only present in the development branch (0.11.0dev). So, if you are interested in testing it, you need to install Mitiq by cloning or forking the repository (https://mitiq.readthedocs.io/en/v0.5.0/contributing.html#development-install).

This is the result of your code in my local environment:

#! pip install qiskit==0.25  # Only if necessary

import numpy as np

import pennylane as qml
from mitiq import zne

with qml.tape.QuantumTape() as tape:
    qml.RX(np.pi / 2, wires=[0])
    qml.CNOT(wires=[0, 1])
    # qml.expval(qml.PauliZ(wires=[0]))
    # qml.expval(qml.PauliZ(wires=[1]))

print(tape.draw())

scaled_tape = zne.scaling.fold_global(tape, scale_factor=3)
print(scaled_tape.draw())

import mitiq
mitiq.about()

Output:

0: ──RX(1.57)──╭C──┤  
 1: ────────────╰X──┤  

 0: ──RX(1.57)──╭C──╭C──RX(-1.57)──RX(1.57)──╭C──┤  
 1: ────────────╰X──╰X───────────────────────╰X──┤  

Mitiq: A Python toolkit for implementing error mitigation on quantum computers
==============================================================================
Authored by: Mitiq team, 2020 & later (https://github.com/unitaryfund/mitiq)

Mitiq Version:  0.11.0dev

Core Dependencies
-----------------
Cirq Version:   0.10.0
NumPy Version:  1.20.1
SciPy Version:  1.6.1

Optional Dependencies
---------------------
PyQuil Version: 2.28.2
Qiskit Version: 0.25.0
Braket Version: 1.9.2

Python Version: 3.7.7
Platform Info:  Linux (x86_64)
sassan72 commented 2 years ago

many many thanks. it worked.

sassan72 commented 2 years ago

is it possible to do error mitigation for quantum measurement(readout) with Mitiq?

andreamari commented 2 years ago

many many thanks. it worked.

Great! I hope you'll find Mitiq useful for your tasks.

I am closing this issue. If you have other doubts feel free to ask questions in the mitiq Discord channel (http://discord.unitary.fund/) or open other issues here.

andreamari commented 2 years ago

is it possible to do error mitigation for quantum measurement(readout) with Mitiq?

Not yet, but it's in the roadmap !