# quantum.gate.QuantumState class

**Package: **quantum.gate

**Installation Required:** This functionality requires MATLAB Support Package for Quantum Computing.

## Description

A `QuantumState`

object represents the quantum state of the qubits in a
quantum circuit. This object contains information about the normalized amplitudes of all
possible $${2}^{n}$$ basis states of the *n* qubits that form the quantum
state.

## Creation

Use the `simulate`

function
to simulate a quantum circuit and return the final state of the circuit as a
`QuantumState`

object. Additionally, you can construct a
`QuantumState`

object directly using one of the following syntaxes.

### Description

translates a string containing the letters `s`

= quantum.gate.QuantumState(`basisString`

)`"0"`

, `"1"`

,
`"+"`

, or `"-"`

into a quantum state. Each letter
represents the basis state that one qubit is in, where the first letter maps to the first
qubit and so on.

translates a complex vector of coefficients into a quantum state with normalized
probability amplitudes.`s`

= quantum.gate.QuantumState(`coeffs`

)

The `coeffs`

vector must have length $${2}^{n}$$, where *n* is the number of qubits. The $${2}^{n}$$ elements of `coeffs`

represent the unnormalized
amplitudes for all the possible $${2}^{n}$$ basis states of the qubits in the Z basis. The
`Amplitudes`

property of the returned quantum state is set to
`coeffs/norm(coeffs)`

.

### Input Arguments

## Properties

## Methods

## Examples

## Tips

A quantum state can contain information that is not observable. Only properties of the quantum state that translate into probabilities (magnitude squared of the state amplitudes) are measurable. For example, multiplying every amplitude of a quantum state by –1 or $$\text{exp(i}\theta )$$ has no measurable impact. This type of transformation is called applying a

*global phase*. However, multiplying one of the amplitudes by –1 or $$\text{exp(i}\theta )$$ (applying a*relative phase*) has a measurable impact. If you measure the state directly after applying the relative phase, you do not see a difference in the probabilities. But if you apply additional gate operations on the qubits, you can detect the difference due to the relative phase.To return measurement probabilities of possible states, you can use any of these methods:

`histogram`

,`probability`

, and`querystates`

. You can also use`randsample`

with a specific number of shots to simulate real measurements on physical quantum devices.

## Version History

**Introduced in R2023a**