I've collected here various functions, routines, and other bits of Matlab, Octave and Mathematica code organized by topic, that might save someone, somewhere, from re-inventing the wheel. Some of them are so simple it would probably be quicker to re-code them than find this page, but since you're here anyway…
Comments within the code should be enough to figure out what they do and how to use them (try help <function>
from within Matlab or Octave). No guarantee they work as advertised, but I use them myself so I do correct bugs when I come across them. The Matlab code should run under both Octave and Matlab.
All the Matlab, Octave and Mathematica code linked from this page is released under the GPL license, version 2 or later.
If you make use of this code in your research, consider including a citation to this web page in any resulting publication. Not only is it fair to give credit when you've made use of other people's work, it is important for scientific reproducability to document any code you used to help produce your results. Also, if you found this code useful, then others probably will too! Citing this page helps others find it.
I leave it to your judgement whether you feel your results made sufficient use of this code to warrant a citation; I do not insist on it. But consider whether using this code has been as helpful to your research as the least useful paper you are citing. (Typically, this sets the bar very low!). If so, you should probably include a citation to this web page.
For convenience, all the Matlab/Octave functions related to quantum mechanics and quantum information theory are also available in a single bundle, as well as individually (below).
Return a minimal purification of density matrix \(\rho\).
Pack or unpack scalars \(s\), vectors \(v\), and matrices \(M\) into a single vector, or unpack them again. Arguments to \(vpack\) can be in any order. Argument \(V\) to \(vunpack\) is the vector to be unpacked, the other arguments are used to determine the dimensions of the objects to unpack into (contents of these arguments are ignored).
Intended for use with optimization routines which (used to?) require all optimization parameters to be passed in a single vector.
Solve the following semi-definite program, given in dual (linear matrix inequality) form:
\begin{align*} &\min_x c^T x\\ &\text{subject to }\\ &\quad \Sigma_i F^(k)_i \geq G^(k)\\ &\quad Ax = b. \end{align*}Requires a working SeDuMi installation. (SeDuMi can be made to work under Octave, too.)
Solve the following semi-definite program, given in primal form:
\begin{align*} &\min_X \mathrm{trace}(CX)\\ &\text{subject to }\\ &\quad X \geq 0\\ &\quad \mathrm{tr}(A^{(i)}X) = b^{(i)}. \end{align*}Requires a working SeDuMi installation. (SeDuMi can be made to work under Octave, too.)
Read the internal documentation for the low-down on this one (try help smartplot
at a Matlab/Octave prompt). Essentially, \(smartplot\) returns points sampled from a user-supplied function, which can then be plotted with the built-in plotting functions.
The `smart' part is that a higher density of points is sampled around interesting regions (e.g. turning points). Interesting regions are identified by a user-defined function, so can be anything.
before the one dimensional system, but if it is after it doesn't work.
I am using your partial trace function TrX, but it doesn't work when the dimensions of some systems are one. It works when the system to be traced out isIn particular, there is an error in the fourth line of the following:
n = length(dim); rdim = dim(end:-1:1); keep = [1:n]; keep(sys) = []; dimtrace = prod(dim(sys)); dimkeep = length(p)/dimtrace;
This is because the ones from "dim" were removed but the index of "sys" was not updated. I tried to fix this, simply by updating the "sys". However, although it seems to work with a few simple examples, when I run my code (a large complicated one with endless uses of your TrX function) it doesn't work properly sometimes.
So I thought to ask you to fix it, rather than me fixing it, just to be on the safe side.
Looking forward to hear from you, and thanks for all the functions ;)
Christina
This is amazing summary that I have never seen before !!!
My prayers to You!
Thanks a lot.
Wow, Its fantastic bro. Thanks a lot! especially for the entanglement entropy and concurrence.
Comment: the new version of randRho requires randH but the file says 'nothing'.
Question: in randRho you multiply randH by 10, which in principle has no effect. Is this for numerical stability?
Sir, This is incredible .I wanted to write a code in matlab to read a color image in quantum bits .i was searching for information .I could nt get all information but what ever I have right now is good.
Hi
Have you developed similar codes in Python?
Thanks
Chien
@sfchien #6:
No, I haven't coded Python versions of these. I'm extremely unlikely ever to do so, as I don't use Python for quantum information calculations myself (or do much numerics at all, for that matter).
For someone with decent knowledge of Numpy/Scipy and (more importantly!) a good understanding of the quantum information theory behind them, it shouldn't be too big a task. Want to take it on?
It is a great help to us !! Thanks a lot
Excellently useful. Thanks to the creator.
This is wonderful stuff. I'll be using this in my research, porting this over to python probably. I'll let you know if I build up enough functionality that it would be useful to share!
Leave a comment
All comments are moderated. Clicking submit will open your email client and let you send your comment by email. By submitting your comment you agree to license the content under a Creative Commons Attribution-ShareAlike 4.0 International License.