State preparation
State Preparation Routines
ghz_block(n_qubits)
Generates the abstract ghz state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A ChainBlock representing the GHZ state. |
Examples:
Source code in qadence/states.py
ghz_state(n_qubits, batch_size=1)
Creates a GHZ state.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
batch_size |
How many bitstrings to use.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
Source code in qadence/states.py
is_normalized(wf, atol=NORMALIZATION_ATOL)
Checks if a wave function is normalized.
PARAMETER | DESCRIPTION |
---|---|
wf |
The wave function as a torch tensor.
TYPE:
|
atol |
The tolerance.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A bool. |
Examples:
Source code in qadence/states.py
normalize(wf)
Normalizes a wavefunction or batch of wave functions.
PARAMETER | DESCRIPTION |
---|---|
wf |
Normalized wavefunctions.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
Source code in qadence/states.py
one_block(n_qubits)
Generates the abstract one state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A KronBlock representing the one state. |
Examples:
Source code in qadence/states.py
one_state(n_qubits, batch_size=1)
Generates the one state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
batch_size |
The batch size.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
Source code in qadence/states.py
pmf(wf)
Converts a wave function into a torch Distribution.
PARAMETER | DESCRIPTION |
---|---|
wf |
The wave function as a torch tensor.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.distributions.Distribution. |
Examples:
Source code in qadence/states.py
product_block(bitstring)
Creates an abstract product state from a bitstring.
PARAMETER | DESCRIPTION |
---|---|
bitstring |
A bitstring.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A KronBlock representing the product state. |
Examples:
Source code in qadence/states.py
product_state(bitstring, batch_size=1, endianness=Endianness.BIG, backend=BackendName.PYQTORCH)
Creates a product state from a bitstring.
PARAMETER | DESCRIPTION |
---|---|
bitstring |
A bitstring.
TYPE:
|
batch_size |
Batch size.
TYPE:
|
backend |
The backend to use. Default is "pyqtorch".
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
from qadence.states import product_state
print(product_state("1100", backend="pyqtorch"))
print(product_state("1100", backend="horqrux"))
Source code in qadence/states.py
rand_bitstring(N)
Creates a random bistring.
PARAMETER | DESCRIPTION |
---|---|
N |
The length of the bitstring.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A string. |
Examples:
Source code in qadence/states.py
rand_product_block(n_qubits)
Creates a block representing a random abstract product state.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A KronBlock representing the product state. |
Examples:
Source code in qadence/states.py
rand_product_state(n_qubits, batch_size=1)
Creates a random product state.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
batch_size |
How many bitstrings to use.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
Source code in qadence/states.py
random_state(n_qubits, batch_size=1, backend=BackendName.PYQTORCH, type=StateGeneratorType.HAAR_MEASURE_FAST)
Generates a random state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
backend |
The backend to use.
TYPE:
|
batch_size |
The batch size.
TYPE:
|
type |
StateGeneratorType.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
from qadence.states import random_state, StateGeneratorType
from qadence.states import random_state, is_normalized, pmf
from qadence.types import BackendName
from torch.distributions import Distribution
### We have the following options:
print([g.value for g in StateGeneratorType])
n_qubits = 2
# The default is StateGeneratorType.HAAR_MEASURE_FAST
state = random_state(n_qubits=n_qubits)
print(state)
### Lets initialize a state using random rotations, i.e., StateGeneratorType.RANDOM_ROTATIONS.
random = random_state(n_qubits=n_qubits, type=StateGeneratorType.RANDOM_ROTATIONS)
print(random)
Source code in qadence/states.py
uniform_block(n_qubits)
Generates the abstract uniform state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A KronBlock representing the uniform state. |
Examples:
Source code in qadence/states.py
uniform_state(n_qubits, batch_size=1)
Generates the uniform state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
batch_size |
The batch size.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples:
Source code in qadence/states.py
zero_block(n_qubits)
Generates the abstract zero state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A KronBlock representing the zero state. |
Examples:
Source code in qadence/states.py
zero_state(n_qubits, batch_size=1)
Generates the zero state for a specified number of qubits.
PARAMETER | DESCRIPTION |
---|---|
n_qubits |
The number of qubits for which the zero state is to be generated.
TYPE:
|
batch_size |
The batch size for the zero state.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
A torch.Tensor. |
Examples: