86 lines
5.5 KiB
Plaintext
86 lines
5.5 KiB
Plaintext
---
|
||
title: real_amplitudes (latest version)
|
||
description: API reference for qiskit.circuit.library.real_amplitudes in the latest version of qiskit
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.circuit.library.real_amplitudes
|
||
---
|
||
|
||
<span id="real-amplitudes" />
|
||
|
||
# real\_amplitudes
|
||
|
||
<Class id="qiskit.circuit.library.real_amplitudes" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.3/qiskit/circuit/library/n_local/real_amplitudes.py#L27-L136" signature="qiskit.circuit.library.real_amplitudes(num_qubits, entanglement='reverse_linear', reps=3, skip_unentangled_qubits=False, skip_final_rotation_layer=False, parameter_prefix='θ', insert_barriers=False, name='RealAmplitudes')" modifiers="class">
|
||
Bases:
|
||
|
||
Construct a real-amplitudes 2-local circuit.
|
||
|
||
This circuit is a heuristic trial wave function used, e.g., as ansatz in chemistry, optimization or machine learning applications. The circuit consists of alternating layers of $Y$ rotations and $CX$ entanglements. The entanglement pattern can be user-defined or selected from a predefined set. This circuit is “real amplitudes” since the prepared quantum states will only have real amplitudes.
|
||
|
||
For example a `real_amplitudes` circuit with 2 repetitions on 3 qubits with `"reverse_linear"` entanglement is
|
||
|
||
```python
|
||
┌──────────┐ ░ ░ ┌──────────┐ ░ ░ ┌──────────┐
|
||
┤ Ry(θ[0]) ├─░────────■───░─┤ Ry(θ[3]) ├─░────────■───░─┤ Ry(θ[6]) ├
|
||
├──────────┤ ░ ┌─┴─┐ ░ ├──────────┤ ░ ┌─┴─┐ ░ ├──────────┤
|
||
┤ Ry(θ[1]) ├─░───■──┤ X ├─░─┤ Ry(θ[4]) ├─░───■──┤ X ├─░─┤ Ry(θ[7]) ├
|
||
├──────────┤ ░ ┌─┴─┐└───┘ ░ ├──────────┤ ░ ┌─┴─┐└───┘ ░ ├──────────┤
|
||
┤ Ry(θ[2]) ├─░─┤ X ├──────░─┤ Ry(θ[5]) ├─░─┤ X ├──────░─┤ Ry(θ[8]) ├
|
||
└──────────┘ ░ └───┘ ░ └──────────┘ ░ └───┘ ░ └──────────┘
|
||
```
|
||
|
||
The entanglement can be set using the `entanglement` keyword as string or a list of index-pairs. See the documentation of `n_local()`. Additional options that can be set include the number of repetitions, skipping rotation gates on qubits that are not entangled, leaving out the final rotation layer and inserting barriers in between the rotation and entanglement layers.
|
||
|
||
**Examples**
|
||
|
||
```python
|
||
from qiskit.circuit.library import real_amplitudes
|
||
|
||
ansatz = real_amplitudes(3, reps=2) # create the circuit on 3 qubits
|
||
ansatz.draw("mpl")
|
||
```
|
||
|
||

|
||
|
||
```python
|
||
ansatz = real_amplitudes(3, entanglement="full", reps=2) # it is the same unitary as above
|
||
ansatz.draw("mpl")
|
||
```
|
||
|
||

|
||
|
||
```python
|
||
ansatz = real_amplitudes(3, entanglement="linear", reps=2, insert_barriers=True)
|
||
ansatz.draw("mpl")
|
||
```
|
||
|
||

|
||
|
||
```python
|
||
ansatz = real_amplitudes(4, reps=2, entanglement=[[0,3], [0,2]], skip_unentangled_qubits=True)
|
||
ansatz.draw("mpl")
|
||
```
|
||
|
||

|
||
|
||
**Parameters**
|
||
|
||
* **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – The number of qubits of the RealAmplitudes circuit.
|
||
* **reps** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – Specifies how often the structure of a rotation layer followed by an entanglement layer is repeated.
|
||
* **entanglement** (*BlockEntanglement | Iterable\[BlockEntanglement] | Callable\[\[*[*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")*], BlockEntanglement | Iterable\[BlockEntanglement]]*) – The indices specifying on which qubits the input blocks act. See `n_local()` for detailed information.
|
||
* **skip\_final\_rotation\_layer** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) – Whether a final rotation layer is added to the circuit.
|
||
* **skip\_unentangled\_qubits** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) – If `True`, the rotation gates act only on qubits that are entangled. If `False`, the rotation gates act on all qubits.
|
||
* **parameter\_prefix** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")) – The name of the free parameters.
|
||
* **insert\_barriers** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) – If True, barriers are inserted in between each layer. If False, no barriers are inserted.
|
||
* **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)")) – The name of the circuit.
|
||
|
||
**Returns**
|
||
|
||
A real-amplitudes circuit.
|
||
|
||
**Return type**
|
||
|
||
[QuantumCircuit](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")
|
||
</Class>
|
||
|