diff --git a/README.md b/README.md index b35fe30ecbd63feef55b65d24f2022613c965890..b1684b2d54728a1a326bdb9721c4fd42619b3d4e 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ To generate the documentation, the following additional packages are required: - [numpydoc](https://numpydoc.readthedocs.io/) - [Sphinx-Gallery](https://sphinx-gallery.github.io/) - [mplsignal](https://mplsignal.readthedocs.io/) + - [jupyters-sphinx](https://jupyter-sphinx.readthedocs.io/) ### Using setuptools to create a package diff --git a/docs_sphinx/conf.py b/docs_sphinx/conf.py index 670495e063a727f65a9d6aad5991bbdcc6195042..aae9c64e8b3dc5f825b6c1b58cb396b9a8d3634d 100644 --- a/docs_sphinx/conf.py +++ b/docs_sphinx/conf.py @@ -24,6 +24,7 @@ extensions = [ 'sphinx.ext.intersphinx', 'sphinx_gallery.gen_gallery', 'numpydoc', # Needs to be loaded *after* autodoc. + 'jupyter_sphinx', ] templates_path = ['_templates'] diff --git a/examples/connectmultiplesfgs.py b/examples/connectmultiplesfgs.py index 20d29f22768233fb9a27d407dbc9622b1773e356..2a0786010f3efa9b90592362a1320f8eb6c1bbf1 100644 --- a/examples/connectmultiplesfgs.py +++ b/examples/connectmultiplesfgs.py @@ -13,94 +13,47 @@ interest to "flatten" the SFGs, i.e., get a resulting SFG not containing other SFGs but the operations of these. To do this, one will have to use the method :func:`~b_asic.signal_flow_graph.SFG.connect_external_signals_to_components`. -This example illustrates how this can be done. -""" +This example illustrates how it can be done. + +.. jupyter-execute:: + + from b_asic.sfg_generators import wdf_allpass + from b_asic.signal_flow_graph import SFG + from b_asic.special_operations import Input, Output + + # Generate allpass branches for fifth-ordet LWDF filter + allpass1 = wdf_allpass([0.2, 0.5]) + allpass2 = wdf_allpass([-0.5, 0.2, 0.5]) + + in_lwdf = Input() + allpass1 << in_lwdf + allpass2 << in_lwdf + out_lwdf = Output((allpass1 + allpass2) * 0.5) + + # Create SFG of LWDF with two internal SFGs + sfg_with_sfgs = SFG( + [in_lwdf], [out_lwdf], name="LWDF with separate internals SFGs for allpass branches" + ) + +The resulting SFG looks like: + +.. jupyter-execute:: -from b_asic.sfg_generators import wdf_allpass -from b_asic.signal_flow_graph import SFG -from b_asic.special_operations import Input, Output - -# Generate allpass branches for fifth-ordet LWDF filter -allpass1 = wdf_allpass([0.2, 0.5]) -allpass2 = wdf_allpass([-0.5, 0.2, 0.5]) - -in_lwdf = Input() -allpass1 << in_lwdf -allpass2 << in_lwdf -out_lwdf = Output((allpass1 + allpass2) * 0.5) - -# Create SFG of LWDF with two internal SFGs -sfg_with_sfgs = SFG( - [in_lwdf], [out_lwdf], name="LWDF with separate internals SFGs for allpass branches" -) - -# %% -# Rendering the SFG will result in something like: -# -# .. graphviz:: -# -# digraph { -# rankdir=LR -# in1 [shape=cds] -# in1 -> sfg1 -# in1 -> sfg2 -# out1 [shape=cds] -# cmul1 -> out1 -# sfg1 [shape=ellipse] -# sfg1 -> add1 -# add1 [shape=ellipse] -# sfg2 -> add1 -# sfg2 [shape=ellipse] -# add1 -> cmul1 -# cmul1 [shape=ellipse] -# } -# -# Now, to create a LWDF where the SFGs are flattened. Note that the original SFGs -# ``allpass1`` and ``allpass2`` currently cannot be printed etc after this operation. - -allpass1.connect_external_signals_to_components() -allpass2.connect_external_signals_to_components() -flattened_sfg = SFG([in_lwdf], [out_lwdf], name="Flattened LWDF") - -# %% -# Resulting in: -# -# .. graphviz:: -# -# digraph { -# rankdir=LR -# in1 [shape=cds] -# in1 -> sym2p1 -# in1 -> sym2p4 -# out1 [shape=cds] -# cmul1 -> out1 -# sym2p1 [shape=ellipse] -# sym2p2 -> sym2p1 -# sym2p2 [shape=ellipse] -# sym2p1 -> add1 -# add1 [shape=ellipse] -# sym2p1 -> t1 -# t1 [shape=square] -# t1 -> sym2p2 -# sym2p3 -> add1 -# sym2p3 [shape=ellipse] -# add1 -> cmul1 -# cmul1 [shape=ellipse] -# sym2p4 -> sym2p3 -# sym2p4 [shape=ellipse] -# sym2p5 -> sym2p3 -# sym2p5 [shape=ellipse] -# sym2p3 -> t2 -# t2 [shape=square] -# t2 -> sym2p5 -# t3 -> sym2p5 -# t3 [shape=square] -# sym2p5 -> t3 -# t4 -> sym2p4 -# t4 [shape=square] -# sym2p4 -> t4 -# t5 -> sym2p2 -# t5 [shape=square] -# sym2p2 -> t5 -# } -# + sfg_with_sfgs + + +Now, to create a LWDF where the SFGs are flattened. Note that the original SFGs +``allpass1`` and ``allpass2`` currently cannot be printed etc after this operation. + +.. jupyter-execute:: + + allpass1.connect_external_signals_to_components() + allpass2.connect_external_signals_to_components() + flattened_sfg = SFG([in_lwdf], [out_lwdf], name="Flattened LWDF") + +Resulting in: + +.. jupyter-execute:: + + flattened_sfg +""" diff --git a/requirements_doc.txt b/requirements_doc.txt index cc10b7636aa5aac13bb8f65591bb824e70e4e57a..5112621bc53d459111ac351cf2d9648481a50e42 100644 --- a/requirements_doc.txt +++ b/requirements_doc.txt @@ -3,3 +3,4 @@ furo numpydoc sphinx-gallery mplsignal +jupyter-sphinx