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

Fixed the random unitary generation from the Haar measure (#760) #760

Merged
merged 3 commits into from
Aug 9, 2018

Conversation

ikkoham
Copy link
Contributor

@ikkoham ikkoham commented Aug 9, 2018

Summary

To generate random unitary matrix from a Haar measure, I used scipy.stats.unitary_group.

Fix #519

Copy link
Contributor

@delapuente delapuente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ikkoham than you very much! Can you add a line to the CHANGELOG.md, under the UNRELEASED > Fixed section telling what are you fixing, please?

@ikkoham
Copy link
Contributor Author

ikkoham commented Aug 9, 2018

Thanks, I updated changelog.rst.

@nonhermitian
Copy link
Contributor

It seems the scipy.stats.unitary_group does not implement the Haar measure formula from the referenced publication (https://arxiv.org/abs/math-ph/0609050). They skip the last step. Here is a correct implementation that can be used here:

import math
import numpy as np
import scipy.linalg as la

def haar_unitary(n):
    z = (np.random.randn(n,n) + 1j*np.random.randn(n,n))/math.sqrt(2.0)
    q,r = la.qr(z)
    d = np.diagonal(r)
    ph = d/np.abs(d)
    q = np.multiply(q,ph,q) #This line is missing in the SciPy version.
    return q

@delapuente delapuente changed the title Fix #519 (use scipy.stats.unitary_group) Fixed the random unitary generation from the Haar measure (#760) Aug 9, 2018
@ikkoham
Copy link
Contributor Author

ikkoham commented Aug 9, 2018

Thank you.

Does the following line correspond to the last step?
https://github.com/scipy/scipy/blob/master/scipy/stats/_multivariate.py#L3789

@delapuente
Copy link
Contributor

I think they are the same. I'm going to merge with master. Meanwhile, @nonhermitian, if you have a couple of minutes, could you confirm @ikkoham observation, please.

@nonhermitian
Copy link
Contributor

Ahh, yes it does. Good catch. This is good.

@delapuente delapuente merged commit b2c5251 into Qiskit:master Aug 9, 2018
@ikkoham ikkoham deleted the fix-random-unitary branch August 10, 2018 04:29
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generation of random unitary matrix does not draw matrices from Haar measure
3 participants