Skip to content

Commit

Permalink
fix: remove jupyter-execute blocks
Browse files Browse the repository at this point in the history
The Jupyter Sphinx integration is currently unable to properly suppress
warnings resulting in prints to stderr [1]. This causes the docs to fail
building properly.
Qiskit Terra already removed the usage of `jupyter-execute` statements a
while ago [2], so we are following suit in this regard, too.

[1]: jupyter/jupyter-sphinx#178
[2]: Qiskit/qiskit#9346
  • Loading branch information
mrossinek committed Feb 7, 2023
1 parent 53d17c1 commit c88ff33
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2022.
# (C) Copyright IBM 2021, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -30,7 +30,7 @@ class HyperCubicLattice(Lattice):
tuples of `size`, `edge_parameters`, and `boundary_conditions`.
For example,
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.hamiltonians.lattices import (
BoundaryCondition,
Expand Down
16 changes: 8 additions & 8 deletions qiskit_nature/second_q/operators/fermionic_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FermionicOp(SparseLabelOp):
A ``FermionicOp`` is initialized with a dictionary, mapping terms to their respective
coefficients:
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import FermionicOp
Expand All @@ -62,7 +62,7 @@ class FermionicOp(SparseLabelOp):
If you have very restricted memory resources available, or would like to avoid the additional
copy, the dictionary will be stored by reference if you disable ``copy`` like so:
.. jupyter-execute::
.. code-block:: python
some_big_data = {
"+_0 -_0": 1.0,
Expand Down Expand Up @@ -91,40 +91,40 @@ class FermionicOp(SparseLabelOp):
Addition
.. jupyter-execute::
.. code-block:: python
FermionicOp({"+_1": 1}, num_spin_orbitals=2) + FermionicOp({"+_0": 1}, num_spin_orbitals=2)
Sum
.. jupyter-execute::
.. code-block:: python
sum(FermionicOp({label: 1}, num_spin_orbitals=3) for label in ["+_0", "-_1", "+_2 -_2"])
Scalar multiplication
.. jupyter-execute::
.. code-block:: python
0.5 * FermionicOp({"+_1": 1}, num_spin_orbitals=2)
Operator multiplication
.. jupyter-execute::
.. code-block:: python
op1 = FermionicOp({"+_0 -_1": 1}, num_spin_orbitals=2)
op2 = FermionicOp({"-_0 +_0 +_1": 1}, num_spin_orbitals=2)
print(op1 @ op2)
Tensor multiplication
.. jupyter-execute::
.. code-block:: python
op = FermionicOp({"+_0 -_1": 1}, num_spin_orbitals=2)
print(op ^ op)
Adjoint
.. jupyter-execute::
.. code-block:: python
FermionicOp({"+_0 -_1": 1j}, num_spin_orbitals=2).adjoint()
Expand Down
14 changes: 7 additions & 7 deletions qiskit_nature/second_q/operators/polynomial_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PolynomialTensor(LinearMixin, GroupMixin, TolerancesMixin, Mapping):
made about the *contents* of the keys. However, the length of each key determines the dimension
of the matrix which it maps, too. For example:
.. jupyter-execute::
.. code-block:: python
import numpy as np
Expand All @@ -96,7 +96,7 @@ class PolynomialTensor(LinearMixin, GroupMixin, TolerancesMixin, Mapping):
axis of the matrix, when an operator gets built from the tensor. This means, that the previous
example would expand for example like so:
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import FermionicOp, PolynomialTensor
Expand All @@ -113,28 +113,28 @@ class PolynomialTensor(LinearMixin, GroupMixin, TolerancesMixin, Mapping):
Addition
.. jupyter-execute::
.. code-block:: python
matrix = np.array([[0, 1], [2, 3]], dtype=float)
0.5 * PolynomialTensor({"+-": matrix}) + PolynomialTensor({"+-": matrix})
Operator multiplication
.. jupyter-execute::
.. code-block:: python
tensor = PolynomialTensor({"+-": matrix})
print(tensor @ tensor)
Tensor multiplication
.. jupyter-execute::
.. code-block:: python
print(tensor ^ tensor)
You can also implement more advanced arithmetic via the :meth:`apply` and :meth:`einsum`
methods.
.. jupyter-execute::
.. code-block:: python
print(PolynomialTensor.apply(np.transpose, tensor))
print(PolynomialTensor.apply(np.conjugate, 1j * tensor))
Expand All @@ -148,7 +148,7 @@ class PolynomialTensor(LinearMixin, GroupMixin, TolerancesMixin, Mapping):
it needs to support more than 2-dimensional arrays, we rely on the
`sparse <https://sparse.pydata.org/en/stable/index.html>`_ library.
.. jupyter-execute::
.. code-block:: python
import sparse as sp
Expand Down
20 changes: 10 additions & 10 deletions qiskit_nature/second_q/operators/spin_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SpinOp(SparseLabelOp):
A ``SpinOp`` is initialized with a dictionary, mapping terms to their respective
coefficients. For example:
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import SpinOp
Expand All @@ -72,7 +72,7 @@ class SpinOp(SparseLabelOp):
are :math:`S^x, S^y, S^z` for spin 3/2 system.
The two qutrit Heisenberg model with transverse magnetic field is
.. jupyter-execute::
.. code-block:: python
SpinOp({
"X_0 X_1": -1,
Expand All @@ -88,7 +88,7 @@ class SpinOp(SparseLabelOp):
An example using labels with powers would be:
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import SpinOp
Expand All @@ -99,7 +99,7 @@ class SpinOp(SparseLabelOp):
If you have very restricted memory resources available, or would like to avoid the additional
copy, the dictionary will be stored by reference if you disable ``copy`` like so:
.. jupyter-execute::
.. code-block:: python
some_big_data = {
"X_0 Y_0": 1.0,
Expand Down Expand Up @@ -133,40 +133,40 @@ class SpinOp(SparseLabelOp):
Addition
.. jupyter-execute::
.. code-block:: python
SpinOp({"X_1": 1}, num_spins=2) + SpinOp({"X_0": 1}, num_spins=2)
Sum
.. jupyter-execute::
.. code-block:: python
sum(SpinOp({label: 1}, num_spins=3) for label in ["X_0", "Z_1", "X_2 Z_2"])
Scalar multiplication
.. jupyter-execute::
.. code-block:: python
0.5 * SpinOp({"X_1": 1}, num_spins=2)
Operator multiplication
.. jupyter-execute::
.. code-block:: python
op1 = SpinOp({"X_0 Z_1": 1}, num_spins=2)
op2 = SpinOp({"Z_0 X_0 X_1": 1}, num_spins=2)
print(op1 @ op2)
Tensor multiplication
.. jupyter-execute::
.. code-block:: python
op = SpinOp({"X_0 Z_1": 1}, num_spins=2)
print(op ^ op)
Adjoint
.. jupyter-execute::
.. code-block:: python
SpinOp({"X_0 Z_1": 1j}, num_spins=2).adjoint()
Expand Down
18 changes: 9 additions & 9 deletions qiskit_nature/second_q/operators/vibrational_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VibrationalOp(SparseLabelOp):
A ``VibrationalOp`` is initialized with a dictionary, mapping terms to their respective
coefficients:
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import VibrationalOp
Expand All @@ -67,7 +67,7 @@ class VibrationalOp(SparseLabelOp):
If you have very restricted memory resources available, or would like to avoid the additional
copy, the dictionary will be stored by reference if you disable ``copy`` like so:
.. jupyter-execute::
.. code-block:: python
some_big_data = {
"+_0_0 -_0_0": 1.0,
Expand All @@ -90,7 +90,7 @@ class VibrationalOp(SparseLabelOp):
If :code:`num_modals` is not provided then the maximum :code:`modal_index` per
mode will determine the :code:`num_modals` for that mode.
.. jupyter-execute::
.. code-block:: python
from qiskit_nature.second_q.operators import VibrationalOp
Expand All @@ -112,40 +112,40 @@ class VibrationalOp(SparseLabelOp):
Addition
.. jupyter-execute::
.. code-block:: python
VibrationalOp({"+_1_0": 1}, num_modals=[2, 2]) + VibrationalOp({"+_0_0": 1}, num_modals=[2, 2])
Sum
.. jupyter-execute::
.. code-block:: python
sum(VibrationalOp({label: 1}, num_modals=[1, 1, 1]) for label in ["+_0_0", "-_1_0", "+_2_0 -_2_0"])
Scalar multiplication
.. jupyter-execute::
.. code-block:: python
0.5 * VibrationalOp({"+_1_0": 1}, num_modals=[1, 1])
Operator multiplication
.. jupyter-execute::
.. code-block:: python
op1 = VibrationalOp({"+_0_0 -_1_0": 1}, num_modals=[1, 1])
op2 = VibrationalOp({"-_0_0 +_0_0 +_1_0": 1}, num_modals=[1, 1])
print(op1 @ op2)
Tensor multiplication
.. jupyter-execute::
.. code-block:: python
op = VibrationalOp({"+_0_0 -_1_0": 1}, num_modals=[1, 1])
print(op ^ op)
Adjoint
.. jupyter-execute::
.. code-block:: python
VibrationalOp({"+_0_0 -_1_0": 1j}, num_modals=[1, 1]).adjoint()
Expand Down

0 comments on commit c88ff33

Please sign in to comment.