diff --git a/qiskit/circuit/library/n_local/efficient_su2.py b/qiskit/circuit/library/n_local/efficient_su2.py index a49d62803e33..b7156621ff8b 100644 --- a/qiskit/circuit/library/n_local/efficient_su2.py +++ b/qiskit/circuit/library/n_local/efficient_su2.py @@ -73,6 +73,8 @@ def efficient_su2( .. plot:: :include-source: + from qiskit.circuit.library import efficient_su2 + circuit = efficient_su2(3, reps=1) circuit.draw("mpl") @@ -82,6 +84,7 @@ def efficient_su2( .. plot:: :include-source: + :context: circuit = efficient_su2(4, su2_gates=["rx", "y"], entanglement="circular", reps=1) circuit.draw("mpl") diff --git a/qiskit/circuit/library/n_local/excitation_preserving.py b/qiskit/circuit/library/n_local/excitation_preserving.py index b185e923b1ca..d19be3594e57 100644 --- a/qiskit/circuit/library/n_local/excitation_preserving.py +++ b/qiskit/circuit/library/n_local/excitation_preserving.py @@ -72,6 +72,8 @@ def excitation_preserving( .. plot:: :include-source: + from qiskit.circuit.library import excitation_preserving + ansatz = excitation_preserving(3, reps=1, insert_barriers=True, entanglement="linear") ansatz.draw("mpl") @@ -81,6 +83,7 @@ def excitation_preserving( .. plot:: :include-source: + :context: ansatz = excitation_preserving(3, reps=1, mode="fsim", entanglement=[[0, 2]]) ansatz.draw("mpl") diff --git a/qiskit/circuit/library/n_local/n_local.py b/qiskit/circuit/library/n_local/n_local.py index 2f32a3257c98..cd198e6f8074 100644 --- a/qiskit/circuit/library/n_local/n_local.py +++ b/qiskit/circuit/library/n_local/n_local.py @@ -148,6 +148,8 @@ def n_local( .. plot:: :include-source: + from qiskit.circuit.library import n_local + circuit = n_local(3, "ry", "cx", "linear", reps=2, insert_barriers=True) circuit.draw("mpl") @@ -156,14 +158,16 @@ def n_local( .. plot:: :include-source: + :context: - circuit = n_local(3, ["ry", "rz"], "cz", 'full', reps=1, insert_barriers=True) + circuit = n_local(3, ["ry", "rz"], "cz", "full", reps=1, insert_barriers=True) circuit.draw("mpl") To omit rotation or entanglement layers, the block can be set to an empty list: .. plot:: :include-source: + :context: circuit = n_local(4, [], "cry", reps=2) circuit.draw("mpl") @@ -172,6 +176,7 @@ def n_local( .. plot:: :include-source: + :context: entangler_map = [[0, 1], [2, 0]] circuit = n_local(3, "x", "crx", entangler_map, reps=2) @@ -183,8 +188,9 @@ def n_local( .. plot: :include-source: + :context: - def entanglement(layer_index: int) -> list[list[int]]: + def entanglement(layer_index): if layer_index % 2 == 0: return [[0, 1], [0, 2]] return [[1, 2]] diff --git a/qiskit/circuit/library/n_local/real_amplitudes.py b/qiskit/circuit/library/n_local/real_amplitudes.py index 770f7565129f..b239651daa4c 100644 --- a/qiskit/circuit/library/n_local/real_amplitudes.py +++ b/qiskit/circuit/library/n_local/real_amplitudes.py @@ -70,23 +70,28 @@ def real_amplitudes( .. plot:: :include-source: + from qiskit.circuit.library import real_amplitudes + ansatz = real_amplitudes(3, reps=2) # create the circuit on 3 qubits ansatz.draw("mpl") .. plot:: :include-source: + :context: ansatz = real_amplitudes(3, entanglement="full", reps=2) # it is the same unitary as above ansatz.draw("mpl") .. plot:: :include-source: + :context: ansatz = real_amplitudes(3, entanglement="linear", reps=2, insert_barriers=True) ansatz.draw("mpl") .. plot:: :include-source: + :context: ansatz = real_amplitudes(4, reps=2, entanglement=[[0,3], [0,2]], skip_unentangled_qubits=True) ansatz.draw("mpl")