Skip to main content

Jupyter Notebook 🪐

Jupyter Notebooks (which run IPython, an interactive shell built with python) can be a great way to use arupcomputepy and have been used on previous projects.

Step 1 - Installation

Ensure you have arupcomputepy installed.

Ensure you have python🐍 and Jupyter🪐 installed.

Step 2 - Run Jupyter Notebook

In the correct directory, open up a Command Prompt.

tip

You can open a Command Prompt in a given directory by typing cmd in the File Explorer address bar.

Now run jupyter notebook in the Command Prompt

This should automatically bring up the Notebook Dashboard in your web browser. If this doesn't happen automatically, find the URL printed in the Command Prompt.

Now create a new notebook:

Step 3 - Setup your notebook

You should begin by giving your notebook a title (which will also be it's filename).

A notebook is composed of cells. These can be either markdown or code cells. Markdown cells allow you to insert formatted text between code cells.

Extra information

We cannot extensively cover the use of Jupyter notebooks here, but there are many helpful guides on the internet.

Step 4 - Start writing code

For an explanation of the below code, refer to the getting started guide.

To enable copy-paste, the code is repeated below the screen snip.

warning

You need to remember to run each cell (shortcut: ctrl + enter) to execute the code.

import arupcomputepy

############################################################################################

# set up our connection ArupCompute
jobNumber = '00000000' # for testing only - please use a real job number
connection = arupcomputepy.Connection(jobNumber)

# Set calculation details and inputs
calcID = 5460340 # DesignCheck2 > Examples > SimpleCalculation v145.0.17 https://compute.arup.digital/calcs/5460340

variables = {
'ID': 'Test',
'A': 1,
'B': 2
}

# Note: must use 'simple' or 'full' result type to get HTML from library (the default 'mini' just returns numbers to keep response size down)
response = arupcomputepy.MakeCalculationRequest(connection, calcID, isBatch=False, variables=variables, resultType='simple')

html = response.arupComputeReport_HTML

############################################################################################

from IPython.core.display import display, HTML
display(HTML(html))

Tips

Equations not rendering correctly

If your equations aren't rendering correctly:

  1. Ensure you are in Chrome
  2. Install the jupyterlab-katex package

HTML report

Reports of the Jupyter notebook can be generated with the following command:

jupyter nbconvert Experiment.ipynb --to html

Or without the code cells:

jupyter nbconvert Experiment.ipynb --no-input --to html

PDF report

First you will need to run an extra pip install:

pip install nbconvert[webpdf]

Then you can generate a PDF version of your notebook using the command:

jupyter nbconvert Experiment.ipynd --to webpdf --allow-chromium-download