-
Notifications
You must be signed in to change notification settings - Fork 1
Run all the jupyter notebooks from the example directory as functional tests in CI #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5e9dba1
47eb806
10b833d
cb9c891
af5abb4
135cdbc
423f9ce
2cba763
fccf0a3
4ddbb45
0088a41
04c4825
325b102
71b2978
3124d51
a40120d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: Testing Jupyter Notebooks | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: | ||
| - "**" | ||
|
|
||
| jobs: | ||
| test: | ||
| timeout-minutes: 30 | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [macos-latest, ubuntu-latest, windows-latest] | ||
| python-version: ['3.10', '3.11', '3.12'] | ||
|
|
||
| runs-on: ${{ matrix.os }} | ||
|
|
||
| steps: | ||
| - name: Check-out repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python environment | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
|
|
||
| - name: Upgrade package installer for Python | ||
| shell: bash | ||
| run: python -m pip install --upgrade pip | ||
|
|
||
| - name: Install Python dependences | ||
| shell: bash | ||
| run: pip install '.[dev]' | ||
|
|
||
| - name: Run tests on Jupyter Notebooks | ||
| shell: bash | ||
| run: pytest --nbmake examples/*ipynb --nbmake-timeout=300 -n=auto | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # © 2021-2024 Contributors to the EasyDiffraction project <https://github.com/easyscience/EasyDiffraction | ||
|
|
||
| import builtins | ||
| import importlib.util | ||
| import time | ||
| from copy import deepcopy | ||
|
|
@@ -59,6 +60,10 @@ | |
| except ImportError: | ||
| print("pandas not installed") | ||
|
|
||
| try: | ||
| from IPython.display import display | ||
| except ImportError: | ||
| pass | ||
|
|
||
| T_ = TypeVar('T_') | ||
|
|
||
|
|
@@ -744,7 +749,7 @@ def show_analysis_chart(self): | |
|
|
||
| y_calc = self.calculate_profile() | ||
|
|
||
| peak_idx, _ = find_peaks(y_calc) #, prominence=1) | ||
| peak_idx, _ = find_peaks(y_calc) | ||
| x_bragg = self.experiment.x.data[peak_idx] | ||
| y_bragg = np.zeros_like(x_bragg) | ||
|
|
||
|
|
@@ -759,8 +764,8 @@ def show_analysis_chart(self): | |
| ) | ||
|
|
||
| trace_bragg = go.Scatter( | ||
| x=x_bragg, # np.random.uniform(low=self.experiment.x.data.min(), high=self.experiment.x.data.max(), size=(50,)), | ||
| y=y_bragg, #np.zeros(50), | ||
| x=x_bragg, | ||
| y=y_bragg, | ||
| xaxis='x2', | ||
| yaxis='y2', | ||
| line=dict(color='rgb(230, 171, 2)'), #color=px.colors.qualitative.Plotly[9]), | ||
|
|
@@ -778,7 +783,7 @@ def show_analysis_chart(self): | |
| y=self.background, | ||
| xaxis='x3', | ||
| yaxis='y3', | ||
| line=dict(color='gray'), # default: width=2? | ||
| line=dict(color='gray'), | ||
| mode='lines', | ||
| name='Background (Ibkg)' | ||
| ) | ||
|
|
@@ -841,27 +846,25 @@ def show_analysis_chart(self): | |
| title_text=x_axis_title, | ||
| anchor='y', | ||
| range=[x_min, x_max], | ||
| # linecolor='blue', | ||
| showline=True, mirror=True, zeroline=False | ||
| ), | ||
| xaxis2=dict( | ||
| matches='x', | ||
| anchor='y2', | ||
| range=[x_min, x_max], | ||
| # linecolor='green', | ||
| showline=True, mirror=True, zeroline=False, showticklabels=False | ||
| ), | ||
| xaxis3=dict( | ||
| matches='x', | ||
| anchor='y3', | ||
| range=[x_min, x_max], | ||
| # linecolor='red', | ||
| showline=True, mirror=True, zeroline=False, showticklabels=False | ||
| ), | ||
| yaxis=dict( | ||
| title_text='Imeas - Icalc', | ||
| domain=[0, resid_height / full_height - 0.01], | ||
| range=[resid_y_min, resid_y_max], | ||
| tickvals=[int(resid_y_min), 0, int(resid_y_max)], | ||
| # nticks = 3, | ||
| showline=True, mirror=True, showgrid=False | ||
| ), | ||
| yaxis2=dict( | ||
|
|
@@ -877,12 +880,14 @@ def show_analysis_chart(self): | |
| ) | ||
|
|
||
| fig = go.Figure(data=data, layout=layout) | ||
|
|
||
| # fig.update_xaxes(showline=True, mirror=True) | ||
| # fig.update_yaxes(showline=True, mirror=True) | ||
|
|
||
| fig.show() | ||
|
|
||
| def is_notebook(self): | ||
| ''' | ||
| Check if the code is running in a Jupyter notebook. | ||
| ''' | ||
| return hasattr(builtins, "__IPYTHON__") | ||
|
|
||
| def print_free_parameters(self): | ||
| ''' | ||
| Print the free parameters. | ||
|
|
@@ -893,11 +898,14 @@ def print_free_parameters(self): | |
| parameters['names'].append(parameter.display_name) | ||
| parameters['values'].append(parameter.raw_value) | ||
| parameters['errors'].append(parameter.error) | ||
| parameters['units'].append(f'{parameter.unit:~H}') | ||
| parameters['units'].append(f'{parameter.unit:~P}') | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at some point, we need to refactor out the plotting and printing methods from
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely agree with that. |
||
| df = pd.DataFrame(parameters) | ||
| df.index += 1 | ||
| df.style.format(precision=5) | ||
| return df | ||
| if self.is_notebook(): | ||
| display(df) | ||
| else: | ||
| print(df) | ||
| else: | ||
| for parameter in self.get_fit_parameters(): | ||
| print(parameter) | ||
|
|
||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should concentrate on a single python version (3.12?) but include more OS-es. This is especially important for assuring file paths are properly set on Windows/Linux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then let's have a full matrix with 3 python versions and 3 os versions to make sure everything is ok for all major combinations. Added to workflow config.