qiskit-documentation/docs/api/qiskit/0.24/qiskit.aqua.components.init...

93 lines
5.8 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Custom
description: API reference for qiskit.aqua.components.initial_states.Custom
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.aqua.components.initial_states.Custom
---
<span id="qiskit-aqua-components-initial-states-custom" />
# qiskit.aqua.components.initial\_states.Custom
<Class id="qiskit.aqua.components.initial_states.Custom" isDedicatedPage={true} github="https://github.com/qiskit-community/qiskit-aqua/tree/stable/0.8/qiskit/aqua/components/initial_states/custom.py" signature="Custom(num_qubits, state='zero', state_vector=None, circuit=None)" modifiers="class">
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`](qiskit.aqua.components.initial_states.Zero "qiskit.aqua.components.initial_states.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 $1$ or $0$.
* 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 $1.0$.
**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 of `complex` or `float` 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 $2^q$, where $q$ 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**](qiskit.aqua.AquaError "qiskit.aqua.AquaError") invalid input
### \_\_init\_\_
<Function id="qiskit.aqua.components.initial_states.Custom.__init__" signature="__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 of `complex` or `float` 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 $2^q$, where $q$ 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**](qiskit.aqua.AquaError "qiskit.aqua.AquaError") invalid input
</Function>
## Methods
| | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| [`__init__`](#qiskit.aqua.components.initial_states.Custom.__init__ "qiskit.aqua.components.initial_states.Custom.__init__")(num\_qubits\[, state, state\_vector, …]) | **type num\_qubits**`int` |
| [`construct_circuit`](#qiskit.aqua.components.initial_states.Custom.construct_circuit "qiskit.aqua.components.initial_states.Custom.construct_circuit")(\[mode, register]) | Construct the statevector of desired initial state. |
## Attributes
| | |
| ---------------------------------------------------------------------------------------------------------------------- | - |
| [`bitstr`](#qiskit.aqua.components.initial_states.Custom.bitstr "qiskit.aqua.components.initial_states.Custom.bitstr") | |
### bitstr
<Attribute id="qiskit.aqua.components.initial_states.Custom.bitstr" />
### construct\_circuit
<Function id="qiskit.aqua.components.initial_states.Custom.construct_circuit" signature="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](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") or numpy.ndarray
**Raises**
[**AquaError**](qiskit.aqua.AquaError "qiskit.aqua.AquaError") when mode is not vector or circuit.
</Function>
</Class>