432 lines
17 KiB
Plaintext
432 lines
17 KiB
Plaintext
---
|
||
title: PauliTwoDesign (latest version)
|
||
description: API reference for qiskit.circuit.library.PauliTwoDesign in the latest version of qiskit
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: class
|
||
python_api_name: qiskit.circuit.library.PauliTwoDesign
|
||
---
|
||
|
||
# PauliTwoDesign
|
||
|
||
<Class id="qiskit.circuit.library.PauliTwoDesign" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/library/n_local/pauli_two_design.py#L24-L141" signature="qiskit.circuit.library.PauliTwoDesign(num_qubits=None, reps=3, seed=None, insert_barriers=False, name='PauliTwoDesign')" modifiers="class">
|
||
Bases: [`TwoLocal`](qiskit.circuit.library.TwoLocal "qiskit.circuit.library.n_local.two_local.TwoLocal")
|
||
|
||
The Pauli Two-Design ansatz.
|
||
|
||
This class implements a particular form of a 2-design circuit \[1], which is frequently studied in quantum machine learning literature, such as e.g. the investigating of Barren plateaus in variational algorithms \[2].
|
||
|
||
The circuit consists of alternating rotation and entanglement layers with an initial layer of $\sqrt{H} = RY(\pi/4)$ gates. The rotation layers contain single qubit Pauli rotations, where the axis is chosen uniformly at random to be X, Y or Z. The entanglement layers is compromised of pairwise CZ gates with a total depth of 2.
|
||
|
||
For instance, the circuit could look like this (but note that choosing a different seed yields different Pauli rotations).
|
||
|
||
```python
|
||
┌─────────┐┌──────────┐ ░ ┌──────────┐ ░ ┌──────────┐
|
||
q_0: ┤ RY(π/4) ├┤ RZ(θ[0]) ├─■─────░─┤ RY(θ[4]) ├─■─────░──┤ RZ(θ[8]) ├
|
||
├─────────┤├──────────┤ │ ░ ├──────────┤ │ ░ ├──────────┤
|
||
q_1: ┤ RY(π/4) ├┤ RZ(θ[1]) ├─■──■──░─┤ RY(θ[5]) ├─■──■──░──┤ RX(θ[9]) ├
|
||
├─────────┤├──────────┤ │ ░ ├──────────┤ │ ░ ┌┴──────────┤
|
||
q_2: ┤ RY(π/4) ├┤ RX(θ[2]) ├─■──■──░─┤ RY(θ[6]) ├─■──■──░─┤ RX(θ[10]) ├
|
||
├─────────┤├──────────┤ │ ░ ├──────────┤ │ ░ ├───────────┤
|
||
q_3: ┤ RY(π/4) ├┤ RZ(θ[3]) ├─■─────░─┤ RX(θ[7]) ├─■─────░─┤ RY(θ[11]) ├
|
||
└─────────┘└──────────┘ ░ └──────────┘ ░ └───────────┘
|
||
```
|
||
|
||
**Examples**
|
||
|
||
```python
|
||
from qiskit.circuit.library import PauliTwoDesign
|
||
circuit = PauliTwoDesign(4, reps=2, seed=5, insert_barriers=True)
|
||
circuit.draw('mpl')
|
||
```
|
||
|
||
![../\_images/qiskit-circuit-library-PauliTwoDesign-1.png](/images/api/qiskit/qiskit-circuit-library-PauliTwoDesign-1.png)
|
||
|
||
**References**
|
||
|
||
**\[1]: Nakata et al., Unitary 2-designs from random X- and Z-diagonal unitaries.**
|
||
|
||
[arXiv:1502.07514](https://arxiv.org/pdf/1502.07514.pdf)
|
||
|
||
**\[2]: McClean et al., Barren plateaus in quantum neural network training landscapes.**
|
||
|
||
[arXiv:1803.11173](https://arxiv.org/pdf/1803.11173.pdf)
|
||
|
||
**Parameters**
|
||
|
||
* **num\_qubits** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *| None*) – The number of qubits of the Pauli Two-Design circuit.
|
||
* **reps** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")) – Specifies how often a block consisting of a rotation layer and entanglement layer is repeated.
|
||
* **seed** ([*int*](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)") *| None*) – The seed for randomly choosing the axes of the Pauli rotations.
|
||
* **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. Defaults to `False`.
|
||
|
||
## Attributes
|
||
|
||
### ancillas
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.ancillas">
|
||
A list of `AncillaQubit`s in the order that they were added. You should not mutate this.
|
||
</Attribute>
|
||
|
||
### calibrations
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.calibrations">
|
||
Return calibration dictionary.
|
||
|
||
The custom pulse definition of a given gate is of the form `{'gate_name': {(qubits, params): schedule}}`
|
||
</Attribute>
|
||
|
||
### clbits
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.clbits">
|
||
A list of `Clbit`s in the order that they were added. You should not mutate this.
|
||
</Attribute>
|
||
|
||
### data
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.data">
|
||
The circuit data (instructions and context).
|
||
|
||
**Returns**
|
||
|
||
a list-like object containing the [`CircuitInstruction`](qiskit.circuit.CircuitInstruction "qiskit.circuit.CircuitInstruction")s for each instruction.
|
||
|
||
**Return type**
|
||
|
||
QuantumCircuitData
|
||
</Attribute>
|
||
|
||
### entanglement
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.entanglement">
|
||
Get the entanglement strategy.
|
||
|
||
**Returns**
|
||
|
||
The entanglement strategy, see `get_entangler_map()` for more detail on how the format is interpreted.
|
||
</Attribute>
|
||
|
||
### entanglement\_blocks
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.entanglement_blocks">
|
||
The blocks in the entanglement layers.
|
||
|
||
**Returns**
|
||
|
||
The blocks in the entanglement layers.
|
||
</Attribute>
|
||
|
||
### flatten
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.flatten">
|
||
Returns whether the circuit is wrapped in nested gates/instructions or flattened.
|
||
</Attribute>
|
||
|
||
### global\_phase
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.global_phase">
|
||
The global phase of the current circuit scope in radians.
|
||
</Attribute>
|
||
|
||
### initial\_state
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.initial_state">
|
||
Return the initial state that is added in front of the n-local circuit.
|
||
|
||
**Returns**
|
||
|
||
The initial state.
|
||
</Attribute>
|
||
|
||
### insert\_barriers
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.insert_barriers">
|
||
If barriers are inserted in between the layers or not.
|
||
|
||
**Returns**
|
||
|
||
`True`, if barriers are inserted in between the layers, `False` if not.
|
||
</Attribute>
|
||
|
||
### instances
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.instances" attributeValue="189" />
|
||
|
||
### layout
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.layout">
|
||
Return any associated layout information about the circuit
|
||
|
||
This attribute contains an optional [`TranspileLayout`](qiskit.transpiler.TranspileLayout "qiskit.transpiler.TranspileLayout") object. This is typically set on the output from [`transpile()`](compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") or [`PassManager.run()`](qiskit.transpiler.PassManager#run "qiskit.transpiler.PassManager.run") to retain information about the permutations caused on the input circuit by transpilation.
|
||
|
||
There are two types of permutations caused by the [`transpile()`](compiler#qiskit.compiler.transpile "qiskit.compiler.transpile") function, an initial layout which permutes the qubits based on the selected physical qubits on the [`Target`](qiskit.transpiler.Target "qiskit.transpiler.Target"), and a final layout which is an output permutation caused by [`SwapGate`](qiskit.circuit.library.SwapGate "qiskit.circuit.library.SwapGate")s inserted during routing.
|
||
</Attribute>
|
||
|
||
### metadata
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.metadata">
|
||
Arbitrary user-defined metadata for the circuit.
|
||
|
||
Qiskit will not examine the content of this mapping, but it will pass it through the transpiler and reattach it to the output, so you can track your own metadata.
|
||
</Attribute>
|
||
|
||
### num\_ancillas
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_ancillas">
|
||
Return the number of ancilla qubits.
|
||
</Attribute>
|
||
|
||
### num\_captured\_vars
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_captured_vars">
|
||
The number of real-time classical variables in the circuit marked as captured from an enclosing scope.
|
||
|
||
This is the length of the `iter_captured_vars()` iterable. If this is non-zero, [`num_input_vars`](#qiskit.circuit.library.PauliTwoDesign.num_input_vars "qiskit.circuit.library.PauliTwoDesign.num_input_vars") must be zero.
|
||
</Attribute>
|
||
|
||
### num\_clbits
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_clbits">
|
||
Return number of classical bits.
|
||
</Attribute>
|
||
|
||
### num\_declared\_vars
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_declared_vars">
|
||
The number of real-time classical variables in the circuit that are declared by this circuit scope, excluding inputs or captures.
|
||
|
||
This is the length of the `iter_declared_vars()` iterable.
|
||
</Attribute>
|
||
|
||
### num\_input\_vars
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_input_vars">
|
||
The number of real-time classical variables in the circuit marked as circuit inputs.
|
||
|
||
This is the length of the `iter_input_vars()` iterable. If this is non-zero, [`num_captured_vars`](#qiskit.circuit.library.PauliTwoDesign.num_captured_vars "qiskit.circuit.library.PauliTwoDesign.num_captured_vars") must be zero.
|
||
</Attribute>
|
||
|
||
### num\_layers
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_layers">
|
||
Return the number of layers in the n-local circuit.
|
||
|
||
**Returns**
|
||
|
||
The number of layers in the circuit.
|
||
</Attribute>
|
||
|
||
### num\_parameters
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_parameters">
|
||
The number of parameter objects in the circuit.
|
||
</Attribute>
|
||
|
||
### num\_parameters\_settable
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_parameters_settable">
|
||
Return the number of settable parameters.
|
||
|
||
**Returns**
|
||
|
||
The number of possibly distinct parameters.
|
||
</Attribute>
|
||
|
||
### num\_qubits
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_qubits">
|
||
Returns the number of qubits in this circuit.
|
||
|
||
**Returns**
|
||
|
||
The number of qubits.
|
||
</Attribute>
|
||
|
||
### num\_vars
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.num_vars">
|
||
The number of real-time classical variables in the circuit.
|
||
|
||
This is the length of the `iter_vars()` iterable.
|
||
</Attribute>
|
||
|
||
### op\_start\_times
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.op_start_times">
|
||
Return a list of operation start times.
|
||
|
||
This attribute is enabled once one of scheduling analysis passes runs on the quantum circuit.
|
||
|
||
**Returns**
|
||
|
||
List of integers representing instruction start times. The index corresponds to the index of instruction in `QuantumCircuit.data`.
|
||
|
||
**Raises**
|
||
|
||
[**AttributeError**](https://docs.python.org/3/library/exceptions.html#AttributeError "(in Python v3.13)") – When circuit is not scheduled.
|
||
</Attribute>
|
||
|
||
### ordered\_parameters
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.ordered_parameters">
|
||
The parameters used in the underlying circuit.
|
||
|
||
This includes float values and duplicates.
|
||
|
||
**Examples**
|
||
|
||
```python
|
||
>>> # prepare circuit ...
|
||
>>> print(nlocal)
|
||
┌───────┐┌──────────┐┌──────────┐┌──────────┐
|
||
q_0: ┤ Ry(1) ├┤ Ry(θ[1]) ├┤ Ry(θ[1]) ├┤ Ry(θ[3]) ├
|
||
└───────┘└──────────┘└──────────┘└──────────┘
|
||
>>> nlocal.parameters
|
||
{Parameter(θ[1]), Parameter(θ[3])}
|
||
>>> nlocal.ordered_parameters
|
||
[1, Parameter(θ[1]), Parameter(θ[1]), Parameter(θ[3])]
|
||
```
|
||
|
||
**Returns**
|
||
|
||
The parameters objects used in the circuit.
|
||
</Attribute>
|
||
|
||
### parameter\_bounds
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.parameter_bounds">
|
||
The parameter bounds for the unbound parameters in the circuit.
|
||
|
||
**Returns**
|
||
|
||
A list of pairs indicating the bounds, as (lower, upper). None indicates an unbounded parameter in the corresponding direction. If `None` is returned, problem is fully unbounded.
|
||
</Attribute>
|
||
|
||
### parameters
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.parameters">
|
||
The parameters defined in the circuit.
|
||
|
||
This attribute returns the [`Parameter`](qiskit.circuit.Parameter "qiskit.circuit.Parameter") objects in the circuit sorted alphabetically. Note that parameters instantiated with a [`ParameterVector`](qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") are still sorted numerically.
|
||
|
||
**Examples**
|
||
|
||
The snippet below shows that insertion order of parameters does not matter.
|
||
|
||
```python
|
||
>>> from qiskit.circuit import QuantumCircuit, Parameter
|
||
>>> a, b, elephant = Parameter("a"), Parameter("b"), Parameter("elephant")
|
||
>>> circuit = QuantumCircuit(1)
|
||
>>> circuit.rx(b, 0)
|
||
>>> circuit.rz(elephant, 0)
|
||
>>> circuit.ry(a, 0)
|
||
>>> circuit.parameters # sorted alphabetically!
|
||
ParameterView([Parameter(a), Parameter(b), Parameter(elephant)])
|
||
```
|
||
|
||
Bear in mind that alphabetical sorting might be unintuitive when it comes to numbers. The literal “10” comes before “2” in strict alphabetical sorting.
|
||
|
||
```python
|
||
>>> from qiskit.circuit import QuantumCircuit, Parameter
|
||
>>> angles = [Parameter("angle_1"), Parameter("angle_2"), Parameter("angle_10")]
|
||
>>> circuit = QuantumCircuit(1)
|
||
>>> circuit.u(*angles, 0)
|
||
>>> circuit.draw()
|
||
┌─────────────────────────────┐
|
||
q: ┤ U(angle_1,angle_2,angle_10) ├
|
||
└─────────────────────────────┘
|
||
>>> circuit.parameters
|
||
ParameterView([Parameter(angle_1), Parameter(angle_10), Parameter(angle_2)])
|
||
```
|
||
|
||
To respect numerical sorting, a [`ParameterVector`](qiskit.circuit.ParameterVector "qiskit.circuit.ParameterVector") can be used.
|
||
|
||
```python
|
||
>>> from qiskit.circuit import QuantumCircuit, Parameter, ParameterVector
|
||
>>> x = ParameterVector("x", 12)
|
||
>>> circuit = QuantumCircuit(1)
|
||
>>> for x_i in x:
|
||
... circuit.rx(x_i, 0)
|
||
>>> circuit.parameters
|
||
ParameterView([
|
||
ParameterVectorElement(x[0]), ParameterVectorElement(x[1]),
|
||
ParameterVectorElement(x[2]), ParameterVectorElement(x[3]),
|
||
..., ParameterVectorElement(x[11])
|
||
])
|
||
```
|
||
|
||
**Returns**
|
||
|
||
The sorted [`Parameter`](qiskit.circuit.Parameter "qiskit.circuit.Parameter") objects in the circuit.
|
||
</Attribute>
|
||
|
||
### preferred\_init\_points
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.preferred_init_points">
|
||
The initial points for the parameters. Can be stored as initial guess in optimization.
|
||
|
||
**Returns**
|
||
|
||
The initial values for the parameters, or None, if none have been set.
|
||
</Attribute>
|
||
|
||
### prefix
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.prefix" attributeValue="'circuit'" />
|
||
|
||
### qregs
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.qregs" attributeTypeHint="list[QuantumRegister]">
|
||
A list of the `QuantumRegister`s in this circuit. You should not mutate this.
|
||
</Attribute>
|
||
|
||
### qubits
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.qubits">
|
||
A list of `Qubit`s in the order that they were added. You should not mutate this.
|
||
</Attribute>
|
||
|
||
### reps
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.reps">
|
||
The number of times rotation and entanglement block are repeated.
|
||
|
||
**Returns**
|
||
|
||
The number of repetitions.
|
||
</Attribute>
|
||
|
||
### rotation\_blocks
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.rotation_blocks">
|
||
The blocks in the rotation layers.
|
||
|
||
**Returns**
|
||
|
||
The blocks in the rotation layers.
|
||
</Attribute>
|
||
|
||
### name
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.name" attributeTypeHint="str">
|
||
A human-readable name for the circuit.
|
||
</Attribute>
|
||
|
||
### cregs
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.cregs" attributeTypeHint="list[ClassicalRegister]">
|
||
A list of the `ClassicalRegister`s in this circuit. You should not mutate this.
|
||
</Attribute>
|
||
|
||
### duration
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.duration" attributeTypeHint="int | float | None">
|
||
The total duration of the circuit, set by a scheduling transpiler pass. Its unit is specified by [`unit`](#qiskit.circuit.library.PauliTwoDesign.unit "qiskit.circuit.library.PauliTwoDesign.unit").
|
||
</Attribute>
|
||
|
||
### unit
|
||
|
||
<Attribute id="qiskit.circuit.library.PauliTwoDesign.unit">
|
||
The unit that [`duration`](#qiskit.circuit.library.PauliTwoDesign.duration "qiskit.circuit.library.PauliTwoDesign.duration") is specified in.
|
||
</Attribute>
|
||
</Class>
|
||
|