-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some Qiskit gates are not supported (during the internal conversion to Cirq) #1073
Comments
Logistically, I suggest closing #558 and using this issue to track to avoid duplicates. |
This issue had no activity for 2 months, and will be closed in one week unless there is new activity. Cheers! |
This issue had no activity for 4 months, and will be closed in 2 weeks unless there is new activity. Cheers! |
Scope of this ticket is twofold:
For milestone 0.25 lets complete point 1, and add support for failing gates that are straightforward to fix. |
I can work on this issue |
Hi @andreamari ! I'm working on this issue and I find Qiskit works now with OpenQASM3 and cirq with OpenQASM2, and using less gates than qiskit, so my question is convenient to do a function to converts OpenQASM3 to OpenQASM2 and include the equivalents gates, for example cu(pi/2, pi/2, pi/2, 0) q[1], q[0]; will be p(0) q[1]; |
Hi @MaldoAlberto, Thanks for isolating the root of problem so well! Two less dangerous solutions are perhaps the following:
Note that the last step is not as easy as it seems, since the pipeline of conversion layers in |
That's true! I can try to do both. Additionally, I'll examine the conversion in 'qiskit.Quantum' to resolve it as soon as possible. Thank you for your suggestions. |
|
Let's check if the original statement of this issue is still valid for the new Qiskit 1.0 integration. If so, I suggest splitting the issue into separate ones for each gate. |
The original statement, as well as the rest of the discussion, still hold for Qiskit 1.0. In order to reproduce the issue, one can run a small modification of the code snippet from #558 (the modifications were to make the snippet compatible with the latest qiskit packages): import functools
from mitiq.interface.mitiq_qiskit import initialized_depolarizing_noise
from qiskit_aer import QasmSimulator
from qiskit import QuantumRegister, ClassicalRegister, transpile
from qiskit import QuantumCircuit
from qiskit.circuit.library import QFT
from mitiq.zne import execute_with_zne
def qs_noisy_simulation(circuit: QuantumCircuit, correct_bitstring, shots: int = 1) -> float:
noise_model = initialized_depolarizing_noise(noise_level=0.02)
backend = QasmSimulator(noise_model=noise_model)
# Transpile the circuit so it can be properly run
exec_circuit = transpile(
circuit,
backend=backend,
basis_gates=noise_model.basis_gates if noise_model else None,
optimization_level=0, # Important to preserve folded gates.
)
# Run the circuit
job = backend.run(exec_circuit, shots=shots)
return job.result().get_counts().get(correct_bitstring, 0.0) / shots
q = QuantumRegister(5,'q')
c = ClassicalRegister(5,'c')
circuit = QuantumCircuit(q,c)
circuit.x(q[0])
circuit.x(q[2])
circuit.x(q[4])
circuit &= QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=False, insert_barriers=True, name='qft')
circuit &= QFT(num_qubits=5, approximation_degree=0, do_swaps=True, inverse=True, insert_barriers=True, name='qft')
circuit.measure(q,c)
print(circuit)
correct_bitstring = "11111"
unmitigated = qs_noisy_simulation(circuit, correct_bitstring)
# circuit = qiskit.compiler.transpile(circuit, basis_gates=["u1", "u2", "u3", "cx"])
mitigated = execute_with_zne(circuit, functools.partial(qs_noisy_simulation, correct_bitstring=correct_bitstring))
print(unmitigated)
print(mitigated) The commented transpile statement (as suggested by @rmlarose in #558) makes it work, but it's not clear to the user that such a step is required for circuits with certain unsupported gates. I am keeping the discussion here, and not splitting it in multiple issues, because the solution may be general and agnostic of the specific unsupported gate, e.g., @MaldoAlberto's suggestion to support a QASM3-->2 compiler would achieve that 1. Footnotes
|
@nathanshammah @andreamari Do you think transpiling to a fixed set of basis gates as a fallback each time a gate is not supported could be a viable option? I know that for QEM we generally want to keep the circuit we are manipulating as close as possible to the original input circuit, but perhaps QEM on a transpiled version of the circuit is still better than no QEM whatsoever? Any thoughts? |
For me this could be a viable option, possibly with a warning and with the option to disable this compilation. We'd need to discuss the default. |
@nathanshammah OK, great, I will create a separate issue for the transpiling solution than. |
Makes sense to me! |
FYI: I just added the ECRGate to the list of non-supported gates in the description of this issue. |
@andreamari Is there anything else I can do to fully resolve this issue as you mentioned it in #2579? Apart from adding |
Hi @gluonhiggs, thanks for your interest and help! The utopic ideal solution would be a faithful conversion of gates, without the need of using fallback decompositions. But we know that this is a non-trivial problem. See e.g. the old comments above in this issue. |
I have added a new PR here. I hope it can fully resolve this without the need to modify Cirq.
|
Some Qiskit gates are not supported (during the internal conversion to Cirq).
It would be good to support more gates.
Since we are relying on Cirq conversion functions, a possible way to do achieve can be via up-streaming these requests to Cirq.
Gates that are currently not supported (please add more if you know more):
sx
= \sqrt{X} : up-to-a-phase equivalent to RX(pi/2)cu1
(see QFT circuit containing CU1 gates cannot be converted to internal mitiq circuit #558)PhaseGate(theta)
= up-to-a-phase equivalent to RZ(theta)u(theta)
ECRGate
: echoed cross-resonance (ECR) gate.The text was updated successfully, but these errors were encountered: