Skip to content

Improve ease-of-use of code in the User Guide #336

Description

@colleenjg

Problem: The current formatting code in the user guide adds a barrier to easily copying and running the example code. See the Meet the Data Objects section, for example.

If the top-right corner copy button is used, chevrons and ellipses are copied alongside the code. They then have to be removed for the code to run

>>> import numpy as np
>>> from torch_brain.data import RegularTimeSeries

>>> behavior = RegularTimeSeries(
...     sampling_rate=100.0,  # in Hz
...     hand_vel=np.random.randn(1000, 2),
...     eye_pos=np.random.randn(1000, 2),
...     pupil_size=np.random.randn(1000),
... )

Alternatively, if the code is selected and copied, the chevrons and ellipses are ignored. However, printed outputs are still copied and they have to be manually removed to run the code. Relatedly, once the code is copied into a single notebook cell, lines like behavior only work as intended (approximately as print(behavior)) if they are the last command in the cell.

Solution: I'm not sure yet, but I'll look into a few options.

Ideally we want to maintain the current benefit of showing example outputs in a compact and clear manner, as achieved by:

>>> behavior
RegularTimeSeries(
  hand_vel=[1000, 2],
  eye_pos=[1000, 2],
  pupil_size=[1000]
)

However, we also want the code to be easily copied and run in a notebook, producing equivalent outputs to what is observed in the guide.

Relevant questions:

  1. Do you mind if there are more code blocks that can be copied? That would provide a solution to making lines like behavior functional, and still showing the output right below in the guide. The main alternative I see would be to use more elaborate print statements (e.g., print(f"behavior:\n{behavior}")), and then showing all outputs together each block of code.
  2. Do we want users to be able to download guide pages like this one as notebooks, so they can actively interact with the code?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions