Skip to content
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

DiagonalGate does not raise when diagonal entries do not have modulus 1 #3842

Closed
hhyap opened this issue Feb 14, 2020 · 3 comments · Fixed by #8098
Closed

DiagonalGate does not raise when diagonal entries do not have modulus 1 #3842

hhyap opened this issue Feb 14, 2020 · 3 comments · Fixed by #8098
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@hhyap
Copy link
Contributor

hhyap commented Feb 14, 2020

Information

  • Qiskit Terra version: 0.12.0
  • Python version: 3.6.9
  • Operating system: Linux

What is the current behavior?

diag_gate allows entries whose modulus are not one.

Steps to reproduce the problem

import qiskit
from numpy import exp,pi

backend = qiskit.Aer.get_backend("statevector_simulator")
qc = qiskit.QuantumCircuit(1)
qc.h(0)
qc.diag_gate([exp(1j*pi/8),0],qc.qregs)  # <-- no error here
qiskit.execute(qc,backend).result().to_dict()

What is the expected behavior?

An error should be raised.

Suggested solutions

Line 59 in https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/extensions/quantum_initializer/diag.py#L59:
if not np.abs( np.abs(z) - 1 ) < _EPS:

@hhyap hhyap added the bug Something isn't working label Feb 14, 2020
@ajavadia ajavadia added the good first issue Good for newcomers label Feb 14, 2020
@JiahanBro
Copy link

Hey guys! I would like to give it a try. Just to be sure I understood it correctly, the second entry of the list which is 0 seems to be the problem right? Maybe the if case in Line 59 only checks the first entry, therefore no error is raised?

@Dinesh-byte-cloud
Copy link

hey can I have a shot at this

@Cryoris
Copy link
Contributor

Cryoris commented Jan 19, 2021

There's an old PR that should fix this, #4375. It has some merge conflicts, maybe you can check with @ewinston if you can brush it up, or create a new one based on that 🙂

@1ucian0 1ucian0 changed the title diag_gate does not raise when diagonal entries do not have modulus 1 DiagonalGate does not raise when diagonal entries do not have modulus 1 May 21, 2022
@1ucian0 1ucian0 removed the status: pending PR It has one or more PRs pending to solve this issue label May 21, 2022
1ucian0 added a commit to 1ucian0/qiskit-terra that referenced this issue May 21, 2022
@mergify mergify bot closed this as completed in #8098 May 23, 2022
mergify bot added a commit that referenced this issue May 23, 2022
* Checks if DiagonalGate has modulus 1 - Fixes #3842

Co-authored-by: ewinston <[email protected]>
Co-authored-by: hhyap <[email protected]>

* reno

* Fix release-note typo

Co-authored-by: ewinston <[email protected]>
Co-authored-by: hhyap <[email protected]>
Co-authored-by: Jake Lishman <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment