QPanda3  0.1.0
Supported by OriginQ
Loading...
Searching...
No Matches
State Vector

Prev Tutorial: Density Matrix
Next Tutorial: Kraus


Introduction

The state vector is a core concept in quantum mechanics, used to abstractly represent the quantum state of a quantum system. The following is a detailed introduction to state vectors in the quantum field:

Definition and Existence Space

Definition

Quantum states are represented by vectors in Hilbert space, also known as state vector space or state space, and are called state vectors.

Existence space

The state vector exists in the inner product space. Inner product space is a vector space with an additional inner product structure. The state vector satisfies all the axioms of the vector space and allows for the operation of inner product.

Nature and characteristics

Unit vector

The norm of a state vector is 1, making it a unit vector. Linear combination: Every inner product space has a single norm-orthogonal basis, and the state vector is a linear combination of all the basis vectors of the single norm-orthogonal basis.

Superposition principle of state

The state vector satisfies the linear property, which corresponds to the superposition principle of state in quantum mechanics. That is, if two quantum states are represented by state vectors \(\mathcal{ ψ } _1\) and \(\mathcal{ ψ } _2\), then their superposition state can be represented by a linear combination of these two state vectors.

Probability distribution

The state vector can be seen as a probability distribution that describes all possible measurement results of a quantum system. For each measurement, there is a certain probability of obtaining different results, and the probability distribution of these results depends on the state vector of the system.

In QPanda3 Quantum Information

QPanda3 uses StateVector in Quantum Informaton to abstract and simulate state vectors

Constructing a StateVector object

Here is API doc

Default constructor

The default is to construct a state vector for a quantum system with only one qubit and a current state of all 0s

For internal tensor product operations, the qbit index with the larger value is used as the left operand. For example, when performing a tensor product operation on a quantum system consisting of \(q[0]\), \(q[1]\), and \(q[2]\), the result is \(\left | q[2] \right \rangle \otimes \left | q[1] \right \rangle \otimes \left | q[0] \right \rangle \)

Output

{
{
{(1,0)},
}
{
{(0,0)},
}
}

From qubit total

Specify the total number of qubits in the quantum system, and generate a state vector where the current state of each quantum is 0

For internal tensor product operations, the qbit index with the larger value is used as the left operand. For example, when performing a tensor product operation on a quantum system consisting of \(q[0]\), \(q[1]\), and \(q[2]\), the result is \(\left | q[2] \right \rangle \otimes \left | q[1] \right \rangle \otimes \left | q[0] \right \rangle \)

Output

{
{
{(1,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
}

From a complex array

Construct a state vector based on a given complex array. If the given complex array does not meet the normalization constraint, it will be automatically normalized. If the number of elements in a given complex array is not a power of 2, it will be automatically expanded to a power of 2. This expansion operation will expand the number of elements as little as possible

For internal tensor product operations, the qbit index with the larger value is used as the left operand. For example, when performing a tensor product operation on a quantum system consisting of \(q[0]\), \(q[1]\), and \(q[2]\), the result is \(\left | q[2] \right \rangle \otimes \left | q[1] \right \rangle \otimes \left | q[0] \right \rangle \)

Output

{
{
{(0.0495074,0.0495074)},
}
{
{(0.0990148,0.0990148)},
}
{
{(0.148522,0.148522)},
}
{
{(0.19803,0.19803)},
}
{
{(0.247537,0.247537)},
}
{
{(0.297044,0.297044)},
}
{
{(0.346552,0.346552)},
}
{
{(0.396059,0.396059)},
}
}
{
{
{(0.0495074,0.0495074)},
}
{
{(0.0990148,0.0990148)},
}
{
{(0.148522,0.148522)},
}
{
{(0.19803,0.19803)},
}
{
{(0.247537,0.247537)},
}
{
{(0.297044,0.297044)},
}
{
{(0.346552,0.346552)},
}
{
{(0.396059,0.396059)},
}
}

From a dictionary

Construct a state vector based on the input dictionary

The keys of the dictionary are positive integers, representing the index of the quantum state; The value of the dictionary is the corresponding amplitude. If the normalization constraint is not met, automatic normalization processing will be performed. If the maximum value of the key of a given dictionary element is not a power of 2, it will be automatically expanded to a power of 2. This expansion operation will expand as few elements as possible

For internal tensor product operations, the qbit index with the larger value is used as the left operand. For example, when performing a tensor product operation on a quantum system consisting of \(q[0]\), \(q[1]\), and \(q[2]\), the result is \(\left | q[2] \right \rangle \otimes \left | q[1] \right \rangle \otimes \left | q[0] \right \rangle \)

Output

{
{
{(0,0)},
}
{
{(0.138675,0.138675)},
}
{
{(0,0)},
}
{
{(0.416025,0.416025)},
}
{
{(0.5547,0.5547)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
}

Obtain internal data

Get numpy.ndarray

Get all the internal data in the form of numpy.ndarray

Here is API doc for StateVector.ndarray

Output

data: [0. +0.j 0.13867505+0.13867505j 0. +0.j
0.41602515+0.41602515j 0.5547002 +0.5547002j 0. +0.j
1. +0.j 0. +0.j ]

Get element

Get the value corresponding to a certain state by indexing

Here is API doc for StateVector.dim

Here is API doc for StateVector.at

Output

element in stv:
0j
(0.1386750490563073+0.1386750490563073j)
0j
(0.41602514716892186+0.41602514716892186j)
(0.5547001962252291+0.5547001962252291j)
0j
0j
0j

Evolution with QCircuit

Evolve without updating

Use the quantum circuit QCircuit to evolve the quantum state without updating the internal data of the original StateVector object, and the result is returned as a new StateVector object

Here is API doc for StateVector.evolve

Output

stv2: {
{
{(0,0)},
}
{
{(1,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
}

Evolve with updating

Use the quantum circuit QCircuit to evolve the quantum state and update the internal data of the original StateVector object

Here is API doc for StateVector.update_by_evolve

Output

stv2: {
{
{(0,0)},
}
{
{(1,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
{
{(0,0)},
}
}

Density Matrix

Obtain the corresponding density matrix representation

Here is API doc for StateVector.get_density_matrix

Output

dm: {
{
{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},
}
{
{(0,0)},{(0.0384615,0)},{(0,0)},{(0.115385,0)},{(0.153846,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.115385,0)},{(0,0)},{(0.346154,0)},{(0.461538,0)},{(0,0)},{(0,0)},{(0,0)},
}
{
{(0,0)},{(0.153846,0)},{(0,0)},{(0.461538,0)},{(0.615385,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,0)},{(0,0)},{(0,0)},{(0,0)},
}
{
{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},{(0,0)},
}
}

Purity

Obtain the corresponding purity

Here is API doc for StateVector.purity

Output

purity: (1+0j)

Boolean function

Valid

Determine whether the internal data is legal

Here is API doc for StateVector.is_valid

Output

res: True

Equal

Determine whether the internal data of two state vectors are equal within the default tolerance

Here is API doc

Output

res: True