You profile a vibration-analysis script in your IDE. The total run takes 50 s. The profiler's call tree reports these cumulative times, where cumulative time includes every function a function calls:
Fill in each function's self time in seconds and its self time as a percentage of the 50 s run. Enter whole numbers.
Unlock full course notes by signing up
A script that only works in your session
While testing a strain conversion, you typed gauge_factor = 2.12 in the IDE console. Your saved script strain.py uses gauge_factor but never assigns it. Your IDE is set to execute Run file inside the existing console session, and all afternoon Run file gave sensible strains.
A colleague runs python strain.py in a terminal, using a byte-identical copy of the file and the same Python and package versions. They get:
NameError: name 'gauge_factor' is not defined
Setting up a project so it runs from a clean start
You are starting a new beam-deflection project that needs numpy and scipy. You want the IDE to run it in its own environment, and you want proof that the saved script works without relying on anything left over in memory. Put these steps in the order you should perform them.
An import that fails only in the IDE
You need the pyvisa package to control a lab oscilloscope. In a terminal you run python -m pip install pyvisa, and it reports success. In the same terminal,
python -c "import sys; print(sys.executable)"
prints /usr/local/bin/python3. The IDE's status bar shows the selected interpreter as ~/lab/.venv/bin/python. You restart the IDE's console, but import pyvisa still raises ModuleNotFoundError: No module named 'pyvisa'.
Using self time to predict a speedup
A finite-element model takes 120.0 s to run. The IDE's profiler reports:
assemble_matrix calls element_stiffness. You vectorise the code inside assemble_matrix itself, so that its self time falls by a factor of 3. element_stiffness is untouched and is called the same number of times. Assume every other function's time is unchanged and profiler overhead is negligible.
What is the new total run time? Give your answer in seconds, to one decimal place.