# Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Perform analytic and numeric quantum computations

Contributed by: Wolfram Research, Quantum Computation Framework team

The Wolfram Quantum Framework brings a broad, coherent design for quantum computation, together with a host of leading-edge capabilities and full integration into Mathematica and Wolfram Language. Starting from discrete quantum mechanics, the Framework provides a high-level symbolic representation of quantum bases, states and operators. The Framework can perform measurements and is equipped with various well-known states and operators, such as Bell states and Pauli operators. Using such simulation capabilities as a foundation, one can use the Framework to model and simulate quantum circuits and algorithms, and interoperate with many external quantum platforms from a Wolfram notebook.

All functions and objects in the Wolfram Quantum Framework seamlessly integrate with over 5,000 built-in functions that are accessible through Wolfram Language. The immediate availability of such functions allows one to study a full range of questions around quantum computation and serves as a valuable educational tool.

To install this paclet in your Wolfram Language environment,
evaluate this code:

`PacletInstall["Wolfram/QuantumFramework"]`

To load the code after installation, evaluate this code:

`Needs["Wolfram`QuantumFramework`"]`

This paclet works with Version 13.1 and higher of Wolfram Language.

Note that the big endian convention is in use, such that qubits are labeled left-to-right, starting with 1. For example, the decimal representation of (which means _{1}⊗_{2}⊗_{3}) is 2^{0}x+2^{1}y+2^{2}z.

Additionally, for the eigenvalues of Pauli-Z, there is:

In[1]:= |

Out[1]= |

Denote the eigenstate {1,0} by (which corresponds to +1 eigenvalue), and {0,1} by (which corresponds to the eigenvalue -1).

In the following, we will briefly review some major quantum functionalities in our framework.

A computational basis can be defined by inputting the dimension information as arguments of QuantumBasis. Alternatively, an association can be used, with the basis name are given as the keys and the corresponding basis elements are specified as the values.

Define a 3D quantum basis (computational):

In[2]:= |

Out[2]= |

Given a basis of dimension n, the basis elements will be indexed by the key with :

In[3]:= |

Out[3]= |

With no input, the dimension is set as 2:

In[4]:= |

Out[4]= |

Use QuantumBasis[n,m] to define a basis for *m* qudits of dimension* n* (for which the overall dimension will be ). For example, define a 2×2×2-dimensional quantum basis:

In[5]:= |

Out[5]= |

Use QuantumBasis[{*n _{1},n_{2},…,n_{m}*}] to define an n

In[6]:= |

Out[6]= |

A basis can also be defined as an association with the basis element names as keys and the corresponding vectors as values:

In[7]:= |

Out[7]= |

In[8]:= |

Out[8]= |

There are many 'named' bases built into the quantum framework, including "Computational", "PauliX", "PauliY", "PauliZ" ((or simply "X", "Y" or "Z"), "Fourier", "Identity", "Schwinger", "Pauli", "Dirac" and "Wigner":

In[9]:= |

Out[9]= |

After a basis object has been defined, it is straightforward to construct quantum states and operators. A quantum state is represented by a QuantumState object and a quantum operator is represented by QuantumOperator.

A state can be defined by two arguments: QuantumState[arg_{1},arg_{2}], where arg_{1} specifies amplitudes or the density matrix, and arg_{2} specifies the basis. With no basis specified, the default basis will be the computational basis, the dimension of which depends on the amplitude vector given in arg1.

Define a pure 2D quantum state (qubit) in the Pauli-X basis:

In[10]:= |

Out[10]= |

In[11]:= |

Out[11]= |

If the basis is not specified, the default is the computational basis of dimensions ( qubits):

In[12]:= |

Out[12]= |

In[13]:= |

Out[13]= |

Binary strings can also be used as inputs:

In[14]:= |

Out[14]= |

Many "named" states are available through the framework:

In[15]:= |

Out[15]= |

A state can also be defined by inputting a density matrix:

In[16]:= |

Out[16]= |

Define a generic Bloch vector:

In[17]:= |

In[18]:= |

Out[19]= |

Test to see if it is a mixed state:

In[20]:= |

Out[20]= |

Calculate its von Neumann entropy:

In[21]:= |

Out[21]= |

Compute its purity:

In[22]:= |

Out[22]= |

Note that one can directly use a Bloch vector as an input:

In[23]:= |

Out[23]= |

In[24]:= |

Out[24]= |

Quantum operators can be defined by a matrix or by specifying eigenvalues with respect to a QuantumBasis. Additionally, there are many built-in named operators that can be used.

Define a Pauli-X operator:

In[25]:= |

Out[25]= |

Apply a Pauli-X operator to a symbolic state :

In[26]:= |

Out[26]= |

Test to see if the application of the Pauli-X operator yields the correct state:

In[27]:= |

Out[27]= |

Multi-qubit operators can take specific orders.

For instance, first define the state *α*+*β*:

In[28]:= |

Then, apply a Pauli-X operator on the second qubit only (by defining an order for the operator):

In[29]:= |

Out[29]= |

Test the result:

In[30]:= |

Out[30]= |

For multi-qudit cases, one can define an order or construct the operator using QuantumTensorProduct. For example:

In[31]:= |

Out[31]= |

One can define a "Controlled" operator with specific target and control qudits:

In[32]:= |

Return the control and target qudits:

In[33]:= |

Out[33]= |

Get the action of the operator (*T*-controlled (1, 2)) on :

In[34]:= |

Out[34]= |

In[35]:= |

Out[35]= |

Note that "CT" is also a "named" controlled operator in this framework:

In[36]:= |

Out[36]= |

One can create a new operator by performing some mathematical operations (e.g., exponential, fraction power, etc.) on a quantum operator:

In[37]:= |

Out[37]= |

Show that the result is the same as a rotation operator around *x*:

In[38]:= |

Out[38]= |

Get the fractional power of the NOT operator:

In[39]:= |

Out[39]= |

In[40]:= |

Out[40]= |

In the Wolfram Quantum Framework, one can study projective measurements or, generally, any positive operator-valued measurement (POVM) using QuantumMeasurementOperator.

A measurement can be defined by specifying the corresponding measurement basis.

Measure a 3D system in its state basis:

In[41]:= |

Out[42]= |

In[43]:= |

Out[43]= |

For composite systems, one can measure one or more qudits. This can be done by specifying an order for QuantumMeasurementOperator.

2D×3D composite system:

In[44]:= |

Measure only the first qudit:

In[45]:= |

Out[45]= |

Measure only the second qudit:

In[46]:= |

Out[46]= |

Measure both qudits:

In[47]:= |

Out[47]= |

One can also give a list of POVM elements by which to define the measurement operator:

In[48]:= |

Check that all POVM elements are explicitly positive semidefinite:

In[49]:= |

Out[49]= |

Check the completeness relations:

In[50]:= |

Out[50]= |

Measure POVMs on a quantum state:

In[51]:= |

Get the post-measurement states:

In[52]:= |

Out[52]= |

Get the corresponding probabilities:

In[53]:= |

Out[53]= |

Show that post-measurement states are the same as states initially defined as POVMs:

In[54]:= |

Out[54]= |

In the framework, there are some functionalities to explore the quantum distance, entanglement monotones and partial tracing, as well as other useful features.

Trace out the second subsystem in a 2-qubit state:

In[55]:= |

Out[55]= |

A partial trace can also be applied to QuantumBasis:

In[56]:= |

Out[56]= |

Given a Werner state (two qubits, with probability p), take the partial transpose with respect to qubit-2:

In[57]:= |

Out[57]= |

In[58]:= |

Out[58]= |

To know whether a state is entangled (or part of that state), use QuantumEntangledQ.

Test if W-state of 4-qubits is entangled or not:

In[59]:= |

Out[60]= |

In[61]:= |

Out[61]= |

Test if qubit-1 and 3 are entangled or not:

In[62]:= |

Out[62]= |

In quantum information, there exist notions of distance between quantum states, such as fidelity, trace distance, Bures angle, etc. One can use QuantumDistance to compute the distance between two quantum states with various metrics.

Measure the trace distance between a pure state and a mixed state:

In[63]:= |

In[64]:= |

Out[64]= |

One may create a list of QuantumOperator and/or QuantumMeasurementOperator objects to build a quantum circuit, which can be represented as a QuantumCircuitOperator object.

Construct a quantum circuit that includes a controlled Hadamard gate:

In[65]:= |

Out[66]= |

The wire labels can be customized (for more info, please refer to Diagram documentation):

In[67]:= |

Out[67]= |

Define a combination of control-0 and control-1 qubits:

In[68]:= |

Out[69]= |

Measurement operators can also be added to a quantum circuit. For a single-qubit unitary operator with eigenvalues ±1, a measurement of can be implemented in the following circuit (note that here, Pauli-Y is considered a operator):

In[70]:= |

Out[71]= |

Applying the circuit operators to a quantum state results in a quantum measurement:

In[72]:= |

Out[72]= |

Calculate the state of the second qubit after the measurement by tracing over the first qubit:

In[73]:= |

Out[73]= |

In[74]:= |

Out[74]= |

The post-measurement states of the second qubit should be the same as the Pauli-Y eigenstates.

There are many named circuits in the Wolfram quantum framework:

In[75]:= |

Out[75]= |

quantum phase estimation, for QuantumOperator[{"Phase",2*π*/5}], in four steps (ie using 4-qubits):

In[76]:= |

Out[76]= |

Bernstein-Vazirani circuit, given a secret string:

In[77]:= |

Out[77]= |

Graph circuit, given a graph:

In[78]:= |

Out[78]= |

Grover search algorithm, given a Boolean function:

In[79]:= |

Out[79]= |

Ising-type of interactions and their Trotter-Suzuki decomposition (4th order):

In[80]:= |

In[81]:= |

Out[81]= |

- Wolfram Language built-in symbols
- Paclet dependencies
- Learn More »

Wolfram Language Version 13.1

- 1.4.4 – 21 August 2024
- 1.4.3 – 12 August 2024
- 1.4.2 – 28 June 2024
- 1.4.1 – 22 May 2024
- 1.4.0 – 15 May 2024
- 1.3.7 – 06 May 2024
- 1.3.6 – 24 April 2024
- 1.3.5 – 08 April 2024
- 1.3.4 – 13 March 2024
- 1.3.3 – 14 February 2024
- 1.3.2 – 03 February 2024
- 1.3.1 – 17 January 2024
- 1.3.0 – 14 January 2024
- 1.2.15 – 13 January 2024
- 1.2.14 – 25 December 2023
- 1.2.13 – 21 December 2023
- 1.2.12 – 21 November 2023
- 1.2.11 – 01 November 2023
- 1.2.10 – 19 October 2023
- 1.2.9 – 02 October 2023
- 1.2.8 – 16 September 2023
- 1.2.7 – 12 September 2023
- 1.2.6 – 18 August 2023
- 1.2.5 – 17 August 2023
- 1.2.4 – 03 August 2023
- 1.2.3 – 01 August 2023
- 1.2.2 – 21 July 2023
- 1.2.1 – 06 July 2023
- 1.2.0 – 28 June 2023
- 1.1.4 – 28 June 2023
- 1.1.3 – 14 June 2023
- 1.1.2 – 01 June 2023
- 1.1.1 – 23 May 2023
- 1.1.0 – 05 May 2023
- 1.0.35 – 03 May 2023
- 1.0.34 – 26 April 2023
- 1.0.33 – 19 April 2023
- 1.0.31 – 06 April 2023
- 1.0.30 – 03 April 2023
- 1.0.29 – 08 March 2023
- 1.0.28 – 27 January 2023
- 1.0.27 – 01 January 2023
- 1.0.26 – 03 December 2022
- 1.0.25 – 05 November 2022
- 1.0.24 – 18 October 2022
- 1.0.23 – 11 October 2022
- 1.0.22 – 04 October 2022
- 1.0.21 – 30 September 2022
- 1.0.19 – 15 August 2022
- 1.0.18 – 08 August 2022
- 1.0.17 – 16 July 2022
- 1.0.15 – 25 May 2022
- 1.0.14 – 10 May 2022
- 1.0.13 – 24 April 2022
- 1.0.12 – 05 April 2022
- 1.0.11 – 05 April 2022
- 1.0.10 – 05 April 2022
- 1.0.9 – 05 April 2022
- 1.0.8 – 04 April 2022
- 1.0.6 – 04 April 2022
- 1.0.2 – 18 January 2022
- 0.0.1 – 08 March 2023