# Introductory Tutorial¶

This tutorial will illustrate the basics of how to use `toqito`

. This
will cover how to instantiate and use the fundamental objects that
`toqito`

provides; namely quantum states, channels, and measurements.

This is a user guide for `toqito`

and is not meant to serve as an
introduction to quantum information. For introductory material on quantum
information, please consult “Quantum Information and Quantum Computation” by
Nielsen and Chuang or the freely available lecture notes “Introduction to
Quantum Computing”
by John Watrous.

More advanced tutorials can be found on the tutorials page.

This tutorial assumes you have `toqito`

installed on your machine. If you
do not, please consult the installation instructions.

## States¶

A *quantum state* is a density operator

where \(\mathcal{X}\) is a complex Euclidean space and where \(\text{D}(\cdot)\) represents the set of density matrices, that is, the set of matrices that are positive semidefinite with trace equal to \(1\).

### Quantum States¶

A complete overview of the scope of quantum states can be found here

The standard basis bra vectors given as \(|0\rangle\) and \(|1\rangle\) where

can be defined in `toqito`

as such

```
>>> from toqito.states import basis
>>> # |0>
>>> basis(2, 0)
[[1]
[0]]
>>> # |1>
>>> basis(2, 1)
[[0]
[1]]
```

One may define one of the four Bell states written as

using `toqito`

as

```
>>> import numpy as np
>>> e_0, e_1 = basis(2, 0), basis(2, 1)
>>> u_0 = 1/np.sqrt(2) * (np.kron(e_0, e_0) + np.kron(e_1, e_1))
[[0.70710678],
[0. ],
[0. ],
[0.70710678]]
```

The corresponding density operator of \(u_0\) can be obtained from

In `toqito`

, that can be obtained as

```
>>> rho_0 = u_0 * u_0.conj().T
[0. 0. 0. 0. ]
[0. 0. 0. 0. ]
[0.5 0. 0. 0.5]]
```

Alternatively, we may leverage the `bell`

function in `toqito`

to
generate all four Bell states defined as

in a more concise manner as

```
>>> from toqito.states import bell
>>> import numpy as np
>>> bell(0)
[[0.70710678],
[0. ],
[0. ],
[0.70710678]]
```

The Bell states constitute one such well-known class of quantum states. There are many other classes of states that are widely used in the field of quantum information. For instance, the GHZ state

is a well-known 3-qubit quantum state. We can invoke this using `toqito`

as

```
>>> from toqito.states import ghz
>>> ghz(2, 3).toarray()
[[0.70710678],
[0. ],
[0. ],
[0. ],
[0. ],
[0. ],
[0. ],
[0.70710678]]
```

While the 3-qubit form of the GHZ state is arguably the most notable, it is possible to define a generalized GHZ state

This generalized state may be obtained in `toqito`

as well. For instance,
here is the GHZ state \(\mathbb{C}^{4^{\otimes 7}}\) as

Using `toqito`

, we can see this generates the appropriate generalized GHZ
state.

```
>>> from toqito.states import ghz
>>> ghz(4, 7, np.array([1, 2, 3, 4]) / np.sqrt(30)).toarray()
[[0.18257419],
[0. ],
[0. ],
...,
[0. ],
[0. ],
[0.73029674]])
```

### Properties of Quantum States¶

Given a quantum state, it is often useful to be able to determine certain
*properties* of the state.

For instance, we can check if a quantum state is pure, that is, if the density matrix that describes the state has rank 1.

Any one of the Bell states serve as an example of a pure state

```
>>> from toqito.states import bell
>>> from toqito.state_props import is_pure
>>> rho = bell(0) * bell(0).conj().T
>>> is_pure(rho)
True
```

Another property that is useful is whether a given state is PPT (positive partial transpose), that is, whether the state remains positive after taking the partial transpose of the state.

For quantum states consisting of shared systems of either dimension \(2 \otimes 2\) or \(2 \otimes 3\), the notion of whether a state is PPT serves as a method to determine whether a given quantum state is entangled or separable.

As an example, any one of the Bell states constitute a canonical maximally entangled state over \(2 \otimes 2\) and therefore should not satisfy the PPT criterion.

```
>>> from toqito.states import bell
>>> from toqito.state_props import is_ppt
>>> rho = bell(2) * bell(2).conj().T
>>> is_ppt(rho)
False
```

As we can see, the PPT criterion is `False`

for an entangled state in
\(2 \otimes 2\).

Further properties that one can check via `toqito`

may be found on this page.

### Operations on Quantum States¶

(Coming soon).

### Distance Metrics for Quantum States¶

Given two quantum states, it is often useful to have some way in which to quantify how similar or different one state is from another.

One well known metric is the *fidelity* function defined for two quantum
states. For two states \(\rho\) and \(\sigma\), one defines the
fidelity between \(\rho\) and \(\sigma\) as

where \(|| \cdot ||_1\) denotes the trace norm.

The fidelity fucntion yields a value between \(0\) and \(1\), with \(0\) representing the scenarion where \(\rho\) and \(\sigma\) are as different as can be and where a value of \(1\) indicates a scenario where \(\rho\) and \(\sigma\) are identical.

Let us consider an example in `toqito`

where we wish to calculate the
fidelity function between quantum states that happen to be identitcal.

```
>>> from toqito.states import bell
>>> from toqito.state_metrics import fidelity
>>>
>>> # Define two identical density operators.
>>> rho = bell(0)*bell(0).conj().T
>>> sigma = bell(0)*bell(0).conj().T
>>>
>>> # Calculate the fidelity between `rho` and `sigma`
>>> fidelity(rho, sigma)
1
```

There are a number of other metrics one can compute on two density matrices
including the trace norm, trace distance. These and others are also available
in `toqito`

. For a full list of distance metrics one can compute on
quatum states, consult the docs.

## Channels¶

A *quantum channel* can be defined as a completely positive and trace
preserving linear map.

More formally, let \(\mathcal{X}\) and \(\mathcal{Y}\) represent complex Euclidean spaces and let \(\text{L}(\cdot)\) represent the set of linear operators. Then a quantum channel, \(\Phi\) is defined as

such that \(\Phi\) is completely positive and trace preserving.

### Quantum Channels¶

(Coming soon).

### Properties of Quantum Channels¶

(Coming soon).

### Operations on Quantum Channels¶

(Coming soon).

## Measurements¶

A *measurement* can be defined as a function

satisfying

where \(\Sigma\) represents a set of measurement outcomes and where \(\mu(a)\) represents the measurement operator associated with outcome \(a \in \Sigma\).