qiskit.aqua.components.initial_states.Custom
class Custom(num_qubits, state='zero', state_vector=None, circuit=None)
The custom initial state.
A custom initial state can be created with this component. It allows a state to be defined in the form of custom probability distribution with the state_vector, or by providing a desired circuit to set the state.
Also state can be used having a few pre-defined initial states for convenience:
- ‘zero’: configures the state vector with the zero probability distribution, and is effectively equivalent to the
Zero
initial state. - ‘uniform’: This setting configures the state vector with the uniform probability distribution. All the qubits are set in superposition, each of them being initialized with a Hadamard gate, which means that a measurement will have equal probabilities to become or .
- ‘random’: This setting assigns the elements of the state vector according to a random probability distribution.
The custom initial state will be set from the circuit, the state_vector, or state, in that order. For state_vector the provided custom probability distribution will be internally normalized so the total probability represented is .
Parameters
- num_qubits (
int
) – Number of qubits, has a minimum value of 1. - state (
str
) – Use a predefined state of (‘zero’ | ‘uniform’ | ‘random’) - state_vector (
Union
[ndarray
,StateFn
,None
]) – An optional vector ofcomplex
orfloat
representing the state as a probability distribution which will be normalized to a total probability of 1 when initializing the qubits. The length of the vector must be , where is the num_qubits value. When provided takes precedence over state. - circuit (
Optional
[QuantumCircuit
]) – A quantum circuit for the desired initial state. When provided takes precedence over both state_vector and state.
Raises
AquaError – invalid input
__init__
__init__(num_qubits, state='zero', state_vector=None, circuit=None)
Parameters
- num_qubits (
int
) – Number of qubits, has a minimum value of 1. - state (
str
) – Use a predefined state of (‘zero’ | ‘uniform’ | ‘random’) - state_vector (
Union
[ndarray
,StateFn
,None
]) – An optional vector ofcomplex
orfloat
representing the state as a probability distribution which will be normalized to a total probability of 1 when initializing the qubits. The length of the vector must be , where is the num_qubits value. When provided takes precedence over state. - circuit (
Optional
[QuantumCircuit
]) – A quantum circuit for the desired initial state. When provided takes precedence over both state_vector and state.
Raises
AquaError – invalid input
Methods
__init__ (num_qubits[, state, state_vector, …]) | type num_qubitsint |
construct_circuit ([mode, register]) | Construct the statevector of desired initial state. |
Attributes
bitstr
construct_circuit
construct_circuit(mode='circuit', register=None)
Construct the statevector of desired initial state.
Parameters
- mode – vector or circuit. The vector mode produces the vector. While the circuit constructs the quantum circuit corresponding that vector.
- register – qubits for circuit construction.
Returns
statevector.
Return type
QuantumCircuit or numpy.ndarray
Raises
AquaError – when mode is not ‘vector’ or ‘circuit’.