QI is a Wolfram Mathematica package for quantum information processing. It includes functions for tensor products, partial traces, Schmidt decomposition, and von Neumann entropy. Random state, unitary, and measurement generation enable testing quantum protocols like teleportation and exploring fidelity under noise. The package supports Fourier-Motzkin elimination and serves as a base for tasks like quantum compilation. CITATION: Roger Colbeck, QI “Quantum Information” Mathematica Package,
GitHub: https://github.com/rogercolbeck/QI
QI Manual: https://www-users.york.ac.uk/~rc973/QI/QI_manual.pdf
GitHub: https://github.com/rogercolbeck/QI
QI Manual: https://www-users.york.ac.uk/~rc973/QI/QI_manual.pdf
This is a Wolfram Mathematica package containing commands for implementing functionalities commonly needed in quantum information processing. These are useful for doing theoretical computations on quantum information protocols. For instance, one could easily use it to work through the teleportation protocol with a perfect Bell state, and then to see what happens to the fidelity of the output state when a noisy Bell state is shared instead. The ability to choose random states etc. can be useful for finding counterexamples to particular statements, or for gaining confidence in a statement prior to proving it. The package may form a useful starting point for constructing others, e.g., it has been used for a quantum compiler (see www-users.york.ac.uk/~rc973/UniversalQCompiler.html ).
As examples, it includes functionality for
◼
Taking tensor products
◼
Computing partial traces
◼
Reordering systems within a tensor product
◼
Schmidt decomposition
◼
Computing von Neumann entropies or mutual informations
◼
Generating random states, unitaries, measurements or channels.
There is also a command for Fourier Motzkin elimination.
To use the package, open the file QI.m in Wolfram Mathematica and press “Run All Code”.
To use the package, open the file QI.m in Wolfram Mathematica and press “Run All Code”.
A short manual, examples notebook and useful palette for entering symbols can be found at www-users.york.ac.uk/~rc973/QI_package.html.
Installation
Installation
No special installation is needed. The file QI.m can be downloaded from https://github.com/rogercolbeck/QI. Simply open the file and press Run All Code. However, if you wish to automatically load these functions on starting Mathematica:
1
.Change to your autoload directory (usually the Autoload sub-directory of your user addons directory, found using the command $UserAddOnsDirectory).
2
.Create a subdirectory QI.
3
.Put the file QI.m in this directory.
4
. Rename the file init.m.
A file, https://www-users.york.ac.uk/~rc973/QI/QI_examples.nb collects some simple examples illustrating the use of these functions. A palette, https://www-users.york.ac.uk/~rc973/QI/Palette.nb can also be downloaded which contains some useful symbols (including ⊗).
General Syntax
General Syntax
In order to use these commands, all vectors must be entered as matrices (this makes them of the right “shape” that the same commands (such as tensor product) can be used for both vectors and matrices without modification). That is, to assign the vector to v one would enter v = {{0}, {1}}. It is easy to convert a standard Mathematica vector (i.e., one entered as v = {0, 1}, which I call a list) to this form by using v = Transpose[{v}].
0 |
1 |
The error handling of these commands is basic (although some checks are done, mostly any displayed errors come out of Mathematica’s built-in functions).
Many of the commands use Chop for comparisons of numerical values. By default, Chop treats numbers smaller than as 0. This means that some commands may do the wrong thing with numerical inputs that are smaller than .
Many of the commands use Chop for comparisons of numerical values. By default, Chop treats numbers smaller than
-10
10
-10
10
Examples file for QI Mathematica package
Examples file for QI Mathematica package
Generate a maximally entangled state of two qubits
In[]:=
ent=(1/2)^(1/2)*(KetV[0,2]⊗KetV[0,2]+KetV[1,2]⊗KetV[1,2])
Out[]=
,{0},{0},
1
2
1
2
Make a density operator from this state
In[]:=
rho12=DM[ent];rho12//MatrixForm
Out[]//MatrixForm=
1 2 | 0 | 0 | 1 2 |
0 | 0 | 0 | 0 |
0 | 0 | 0 | 0 |
1 2 | 0 | 0 | 1 2 |
Compute the reduced density operator on the first subsystem
In[]:=
rho1=PT[rho12,{1,0},{2,2}];rho1//MatrixForm
Out[]//MatrixForm=
1 2 | 0 |
0 | 1 2 |
And on the second
In[]:=
rho2=PT[rho12,{0,1},{2,2}];rho2//MatrixForm
Out[]//MatrixForm=
1 2 | 0 |
0 | 1 2 |
This can also be done using QubitPartialTrace
In[]:=
QubitPartialTrace[rho12,{2}]//MatrixForm
Out[]//MatrixForm=
1 2 | 0 |
0 | 1 2 |
Purify rho1
In[]:=
Purify[rho1]
Out[]=
,{0},{0},
1
2
1
2
Apply the tensor product of two Pauli operators to the state
In[]:=
(σ[3]⊗σ[2]).ent//MatrixForm
Out[]//MatrixForm=
0 |
2 |
2 |
0 |
Take another pure state of dimension 8
In[]:=
psi=,,2,,,,,2;
2
33
2
33
2
33
3
22
3
22
2
33
2
33
2
33
Find its Schmidt decomposition assuming it is a 2D system tensored with a 4D system
In[]:=
{c,vecs1,vecs2}=FullSimplify[SchmidtDecomposition[psi,{2,4}]]
,,,,-,,,,,,,{0},-,
21
22
1
22
1
2
1
2
1
2
1
2
5
3
14
2
2
7
3
2
7
7
2
3
1
6
2
3
1
6
Confirm that this is correct
In[]:=
FullSimplify[Sum[c[[i]]*vecs1[[i]]⊗vecs2[[i]],{i,1,Length[c]}]-psi]
Out[]=
{{0},{0},{0},{0},{0},{0},{0},{0}}
Take the tensor product of psi with ent, where psi is on systems 1 and 3 and ent is 2 and 4
In[]:=
tensored=FullSimplify[Tensor[psi,ent,{1,2,1,2},{2,2,4,2}]]
,{0},,{0},,{0},,{0},{0},,{0},,{0},,{0},,,{0},,{0},,{0},,{0},{0},,{0},,{0},,{0},
1
33
1
33
2
33
3
11
2
1
33
1
33
2
33
3
11
2
3
11
2
1
33
1
33
2
33
3
11
2
1
33
1
33
2
33
Tracing out systems 1 and 3 should recover the density matrix of ent
In[]:=
FullSimplify[PT[DM[tensored],{0,1,0,1},{2,2,4,2}]]
Out[]=
,0,0,,{0,0,0,0},{0,0,0,0},,0,0,
1
2
1
2
1
2
1
2
We can also swap the systems in tensored so as to get ent⊗psi
In[]:=
ExchangeSystems[tensored,{3,1,4,2},{2,2,4,2}]-ent⊗psi
{{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0},{0}}
Simultaneously diagonalize two commuting matrices
In[]:=
a=σ[1]⊗σ[1];b=σ[2]⊗σ[2];a.b-b.a
Out[]=
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}
In[]:=
u=SimultaneouslyDiagonalize[a,b][[3]]
Out[]=
-,0,0,,0,-,,0,,0,0,,0,,,0
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
2
In[]:=
u.a.CT[u]//MatrixForm
Out[]//MatrixForm=
-1 | 0 | 0 | 0 |
0 | -1 | 0 | 0 |
0 | 0 | 1 | 0 |
0 | 0 | 0 | 1 |
In[]:=
u.b.CT[u]//MatrixForm
Out[]//MatrixForm=
1 | 0 | 0 | 0 |
0 | -1 | 0 | 0 |
0 | 0 | -1 | 0 |
0 | 0 | 0 | 1 |
Treat ent as an isometry and complete to a unitary
Find the RQ decomposition of a random density operator:
Check the result, and that the matrices have the correct form:
Pick a random channel from dimension 2 to 4 with 10 Kraus operators
Check that it is a valid channel
Act on density operator rho
Find the Choi state of the channel
Returning to the channel will give a smaller Kraus rank (8 is the maximum needed)
Check that it has the same action on rho
This is the same as ChannelCompress
Find the conditional von Neumann entropy of the first qubit with respect to the second in rhop
This is the same as the joint entropy minus the reduced entropy
Pick a random state of 4 qubits with real coefficients
Compute the conditional mutual information between the 3rd and 4th systems given the first
There is symmetry in the labels 1 and 2
It is also invariant under unitaries on the system being conditioned on
Since psi is pure, it should have no entropy
Pick two random density matrices and compute the relative entropy between them
Now choose rho2 without full support
Now compute the alpha=1.5 Renyi entropy of the same states.
Create an 8x8 matrix with symbolic values, treating it as three qubits and compute the partial trace where the first and third systems are traced out
Pick two random 16 dimensional state (4 qubits) with exact values
Compute their trace distance and fidelity
On tracing out the first, third and fourth systems, the distance should decrease and the fidelity increase
Note that QuickDist is faster than Dist in general
Choose a random density operator in dimension 4 and a random measurement with 2 outcomes in dimension 4
Check that it is a valid measurement:
The post-measurement state after applying the measurement to rho and getting the first outcome is
Its trace is the probability of this outcome
Repeat for the second outcome:
We can also define a POVM from these
We might also want to apply this POVM to half of a maximally entangled state
Click on the following output to view its full size version.
The probability of the first outcome is the trace of the upper left 4x4 submatrix:
See the entangled state in basis form, considering it to be a state of 4 qubits
Or the same but treating it as two 4-dimensional systems
Or as a 2 and an 8
Find the optimum POVM to distinguish two states
Calculate the probability of correctly guessing the state using this POVM
This should be the same as 1/2 ( 1 + Dist[rho1, rho2]) :
CITE THIS NOTEBOOK
CITE THIS NOTEBOOK
QI: a package for quantum information processing
by Roger Colbeck
Wolfram Community, STAFF PICKS, November 13, 2024
https://community.wolfram.com/groups/-/m/t/3319957
by Roger Colbeck
Wolfram Community, STAFF PICKS, November 13, 2024
https://community.wolfram.com/groups/-/m/t/3319957