question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Eigenvalues of positive semi definite matrices generated using rand_herm are not random

See original GitHub issue

Describe the issue I was trying to generate random positive semi-definite matrices using the function rand_herm but the eigenvalues clearly don’t seem to be random. For example, if I choose the dimension to be 3, then the eigenvalues are always like 3.something or 4.something or 5.something; if I choose the dimension to be 4, the eigenvalues are always like '4.somethingor5.somethingor6.something`, and similarly for other dimensions.

To Reproduce

import numpy as np
from numpy.linalg import eig

N = 4
for i in range(10):
    E = qutip.rand_herm(N, 0.35, None, True, None)
    w,v=eig(E)
    print('E-value:', w.real)

The terminal output is

E-value: [6.32043755 6.06791959 5.24578891 4.99327095]
E-value: [5.37493846 5.8003551  6.26253682 5.65685425]
E-value: [5.17596435 5.5020902  5.8116183  6.13774415]
E-value: [6.25884718 5.05486132 5.71761238 5.59609612]
E-value: [5.94609905 5.36760945 6.2943825  5.33641017]
E-value: [6.25296302 5.06074548 5.65685425 5.65685425]
E-value: [4.81999397 5.75787997 6.57166109 5.65685425]
E-value: [5.23867334 6.35633232 5.8283425  5.65685425]
E-value: [5.13755732 5.71669004 6.21844559 5.65685425]
E-value: [6.32817223 5.48538456 5.30187642 6.01183208]

Expected Behaviour The eigenvalues should be random.

Your Environment

QuTiP: Quantum Toolbox in Python
================================
Copyright (c) QuTiP team 2011 and later.
Current admin team: Alexander Pitchford, Nathan Shammah, Shahnawaz Ahmed, Neill Lambert, Eric Giguère, Boxi Li, Jake Lishman and Simon Cross.
Board members: Daniel Burgarth, Robert Johansson, Anton F. Kockum, Franco Nori and Will Zeng.
Original developers: R. J. Johansson & P. D. Nation.
Previous lead developers: Chris Granade & A. Grimsmo.
Currently developed through wide collaboration. See https://github.com/qutip for details.

QuTiP Version:      4.7.0.dev0+nogit
Numpy Version:      1.21.1
Scipy Version:      1.7.0
Cython Version:     None
Matplotlib Version: 3.4.2
Python Version:     3.8.11
Number of CPUs:     8
BLAS Info:          OPENBLAS
OPENMP Installed:   False
INTEL MKL Ext:      False
Platform Info:      Windows (AMD64)
Installation path:  C:\Users\acer\anaconda3\envs\learning_qutip\lib\site-packages\qutip
================================================================================
Please cite QuTiP in your publication.
================================================================================
For your convenience a bibtex reference can be easily generated using `qutip.cite()`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jakelishmancommented, Aug 25, 2021

QuTiP doesn’t have one built in at the moment, but toqito can do it as numpy arrays, which you can just wrap in Qobj. There’s no scope for density there, though (and it would be very difficult to do so, I think!).

1reaction
hodgestarcommented, Aug 25, 2021

Supplying negative or zero eigenvalues in the list and pos_def=True is certainly non-sensical input and should possibly return an error (and I think doesn’t at the moment).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensure random matrix to be positive semi definite and of fixed ...
Start with a random column vector v0 and the matrix M you want to find eigenvalues for. Calculate v1=Mv0, set k=1; For as...
Read more >
Random positive semi-definite matrix with given eigenvalues ...
Context: I want to generate random multivariate Gaussians with controlled ellipticity and because the major/minor axes of the distribution have ...
Read more >
Eigenvalues of random matrix conditional on positive ...
Let μ|PD denote this measure conditioned on the event that the matrix is positive semi-definite. What if anything is known about this measure, ......
Read more >
12.4 Positive semi definite matrices and maximum eigenvalues
The definition of positive definite and positive semi - definite matrices, and finding the maximum eigenvalue of such a matrix and the ...
Read more >
generate a positive semi-definite matrices?? - Google Groups
One way to generate a random positive semi-definite 3x3 matrix: a = rand(3,3) ... To check, use the eig function to see that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found