Difference between revisions of "RandomDensityMatrix"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
{{Function | {{Function | ||
|name=RandomDensityMatrix | |name=RandomDensityMatrix | ||
| − | |desc=Generates a random | + | |desc=Generates a random density matrix |
| − | | | + | |rel=[[RandomStateVector]]<br />[[RandomSuperoperator]]<br />[[RandomUnitary]] |
| − | | | + | |cat=[[List of functions#Random_things|Random things]] |
|upd=November 23, 2012 | |upd=November 23, 2012 | ||
| − | |v= | + | |v=0.50}} |
<tt>'''RandomDensityMatrix'''</tt> is a [[List of functions|function]] that generates a random [[density matrix]], uniformly according to the [[Hilbert-Schmidt measure]], the [[Bures measure]], or a version of the [[Haar measure]]. | <tt>'''RandomDensityMatrix'''</tt> is a [[List of functions|function]] that generates a random [[density matrix]], uniformly according to the [[Hilbert-Schmidt measure]], the [[Bures measure]], or a version of the [[Haar measure]]. | ||
| Line 26: | Line 26: | ||
===Random mixed qubits=== | ===Random mixed qubits=== | ||
The following code generates a random mixed state on a 2-level system: | The following code generates a random mixed state on a 2-level system: | ||
| − | < | + | <syntaxhighlight> |
>> rho = RandomDensityMatrix(2) | >> rho = RandomDensityMatrix(2) | ||
| Line 33: | Line 33: | ||
0.1187 -0.0728 + 0.0409i | 0.1187 -0.0728 + 0.0409i | ||
-0.0728 - 0.0409i 0.8813 | -0.0728 - 0.0409i 0.8813 | ||
| − | </ | + | </syntaxhighlight> |
We can verify that this is indeed a valid density matrix as follows: | We can verify that this is indeed a valid density matrix as follows: | ||
| − | < | + | <syntaxhighlight> |
>> trace(rho) | >> trace(rho) | ||
| Line 43: | Line 43: | ||
1 | 1 | ||
| − | >> | + | >> IsPSD(rho) |
ans = | ans = | ||
1 | 1 | ||
| − | </ | + | </syntaxhighlight> |
The following code generates a density matrix with all real entries, chosen according to the [[Bures measure]]: | The following code generates a density matrix with all real entries, chosen according to the [[Bures measure]]: | ||
| − | < | + | <syntaxhighlight> |
>> RandomDensityMatrix(2,1,2,'bures') | >> RandomDensityMatrix(2,1,2,'bures') | ||
| Line 58: | Line 58: | ||
0.1578 0.2259 | 0.1578 0.2259 | ||
0.2259 0.8422 | 0.2259 0.8422 | ||
| − | </ | + | </syntaxhighlight> |
===A larger example of specified rank=== | ===A larger example of specified rank=== | ||
To generate a 6-by-6 density matrix with rank at most 4, you could use the following code: | To generate a 6-by-6 density matrix with rank at most 4, you could use the following code: | ||
| − | < | + | <syntaxhighlight> |
>> rho = RandomDensityMatrix(6,0,4) | >> rho = RandomDensityMatrix(6,0,4) | ||
| Line 79: | Line 79: | ||
4 | 4 | ||
| − | </ | + | </syntaxhighlight> |
| + | |||
| + | {{SourceCode|name=RandomDensityMatrix}} | ||
Revision as of 13:58, 25 September 2014
| RandomDensityMatrix | |
| Generates a random density matrix | |
| Other toolboxes required | none |
|---|---|
| Related functions | RandomStateVector RandomSuperoperator RandomUnitary |
| Function category | Random things |
RandomDensityMatrix is a function that generates a random density matrix, uniformly according to the Hilbert-Schmidt measure, the Bures measure, or a version of the Haar measure.
Syntax
- RHO = RandomDensityMatrix(DIM)
- RHO = RandomDensityMatrix(DIM,RE)
- RHO = RandomDensityMatrix(DIM,RE,K)
- RHO = RandomDensityMatrix(DIM,RE,K,DIST)
Argument descriptions
- DIM: The number of rows (or equivalently, columns) that RHO will have.
- RE (optional, default 0): A flag (either 0 or 1) indicating that RHO should only have real entries (RE = 1) or that it is allowed to have complex entries (RE = 0).
- K (optional, default DIM): The maximal rank of the density matrix to be produced. With probability 1, rank(RHO) = K (if K ≤ DIM).
- DIST (optional, default 'hs'): A string indicating the desired distribution that RHO should be chosen from. It can take on one of three values:
- 'hs': The Hilbert-Schmidt measure.
- 'bures': The Bures measure.
- 'haar': The density matrix is generated by generating a Haar-uniform pure state in $\mathbb{C}^K \otimes \mathbb{C}^{DIM}$ and then tracing out the first subsystem.
Examples
Random mixed qubits
The following code generates a random mixed state on a 2-level system:
>> rho = RandomDensityMatrix(2)
rho =
0.1187 -0.0728 + 0.0409i
-0.0728 - 0.0409i 0.8813We can verify that this is indeed a valid density matrix as follows:
>> trace(rho)
ans =
1
>> IsPSD(rho)
ans =
1The following code generates a density matrix with all real entries, chosen according to the Bures measure:
>> RandomDensityMatrix(2,1,2,'bures')
ans =
0.1578 0.2259
0.2259 0.8422A larger example of specified rank
To generate a 6-by-6 density matrix with rank at most 4, you could use the following code:
>> rho = RandomDensityMatrix(6,0,4)
rho =
0.1750 -0.0299 - 0.0103i -0.0304 - 0.0668i 0.0108 - 0.0176i -0.0294 - 0.0796i -0.0026 + 0.0705i
-0.0299 + 0.0103i 0.1461 -0.0483 + 0.0490i 0.0406 + 0.0422i -0.0064 + 0.1005i 0.0461 + 0.0225i
-0.0304 + 0.0668i -0.0483 - 0.0490i 0.1896 -0.0010 + 0.0652i 0.0156 + 0.0388i -0.0610 - 0.0002i
0.0108 + 0.0176i 0.0406 - 0.0422i -0.0010 - 0.0652i 0.1332 0.1221 + 0.0212i -0.0023 + 0.0264i
-0.0294 + 0.0796i -0.0064 - 0.1005i 0.0156 - 0.0388i 0.1221 - 0.0212i 0.2355 -0.0381 - 0.0789i
-0.0026 - 0.0705i 0.0461 - 0.0225i -0.0610 + 0.0002i -0.0023 - 0.0264i -0.0381 + 0.0789i 0.1206
>> rank(rho)
ans =
4Source code
Click here to view this function's source code on github.