Open
Description
Description of the issue
Greetings there,
Hope all are well. I am trying to implement the quantum_shannon_decomposition.py
in qiskit, and to do that I need to represent ZPowGate
using gates such as Ry, Rz, global phase, and such. To see what the conversion is I used the cirq.qasm()
function, however, the conversion is wrong as can be seen below.
How to reproduce the issue
import cirq
import numpy as np
from numpy.testing import assert_almost_equal
from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator
n_qubits = 1
cirq_qc = cirq.Circuit()
qubits = [cirq.NamedQubit(f'q{i}') for i in range(n_qubits)]
# No global shift case
cirq_qc.append(cirq.ZPowGate(exponent=1.5/np.pi).on(qubits[0]))
qasm_str = cirq.qasm(cirq_qc)
qiskit_qc = QuantumCircuit.from_qasm_str(qasm_str)
qiskit_U = Operator(qiskit_qc).data
cirq_U = cirq.unitary(cirq_qc)
assert_almost_equal(qiskit_U, cirq_U, 8)
During handling of the above exception, another exception occurred:
AssertionError Traceback (most recent call last)
Cell In[78], [line 21](vscode-notebook-cell:?execution_count=78&line=21)
[18](vscode-notebook-cell:?execution_count=78&line=18) qiskit_U = Operator(qiskit_qc).data
[19](vscode-notebook-cell:?execution_count=78&line=19) cirq_U = cirq.unitary(cirq_qc)
---> [21](vscode-notebook-cell:?execution_count=78&line=21) assert_almost_equal(qiskit_U, cirq_U, 8)
File /usr/lib/python3.11/contextlib.py:81, in ContextDecorator.__call__.<locals>.inner(*args, **kwds)
[78](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/usr/lib/python3.11/contextlib.py:78) @wraps(func)
[79](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/usr/lib/python3.11/contextlib.py:79) def inner(*args, **kwds):
[80](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/usr/lib/python3.11/contextlib.py:80) with self._recreate_cm():
---> [81](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/usr/lib/python3.11/contextlib.py:81) return func(*args, **kwds)
File ~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:517, in assert_almost_equal(actual, desired, decimal, err_msg, verbose)
[515](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:515) assert_almost_equal(actuali, desiredi, decimal=decimal)
[516](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:516) except AssertionError:
--> [517](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:517) raise AssertionError(_build_err_msg())
[519](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:519) if isinstance(actual, (ndarray, tuple, list)) \
[520](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:520) or isinstance(desired, (ndarray, tuple, list)):
[521](https://vscode-remote+wsl-002bubuntu.vscode-resource.vscode-cdn.net/home/ace07/Documents/GitHub/QICKIT/.temp/~/Documents/GitHub/QICKIT/.venv/lib/python3.11/site-packages/numpy/testing/_private/utils.py:521) return assert_array_almost_equal(actual, desired, decimal, err_msg)
AssertionError:
Arrays are not almost equal to 8 decimals
ACTUAL: array([[0.73168887-0.68163876j, 0. +0.j ],
[0. +0.j , 0.73168887+0.68163876j]])
DESIRED: array([[1. +0.j , 0. +0.j ],
[0. +0.j , 0.0707372+0.99749499j]])
Cirq version
cirq-core == 1.4.1
Metadata
Assignees
Type
Projects
Status
No status