Skip to content

Dev plotting#16

Open
michael-hirsch-quelements wants to merge 94 commits intoqua-platform:feat/Plotly_toolkitfrom
Quantum-Elements:dev-plotting
Open

Dev plotting#16
michael-hirsch-quelements wants to merge 94 commits intoqua-platform:feat/Plotly_toolkitfrom
Quantum-Elements:dev-plotting

Conversation

@michael-hirsch-quelements
Copy link
Copy Markdown

No description provided.

nulinspiratie and others added 7 commits August 11, 2025 16:11
* removed qiskit experiments dependency. added dependencies to pyproject.toml

* different representation of batchable_list

* version increase

* updates dependecies

* correct batchablelist rep

* updated change log
* add TwoQubitExperimentNodeParameters class

* small refactor

* Update CHANGELOG.md

* adding 2Q features

* added safe guard and fetch for qubit_pair stream variable names

* extend convert_IQ_to_V for qubits and qubit_pairs

* add unwrap phase function for cryoscope

* fix the fetcher

* Update qualibration_libs/parameters/experiment.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* refactor

---------

Co-authored-by: paulQM <paul.jamet@quantum-machines.co>
Co-authored-by: Paul Jamet <113030828+paulQM@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Introduced `QualibrationFigure` for creating customizable plots.
- Added `Overlay` classes for enhanced plot annotations, including `LineOverlay`, `RefLine`, and `ScatterOverlay`.
- Implemented `QubitGrid` for managing qubit layouts in plots.
- Created `PlotTheme` and configuration management for consistent styling.
- Added dataset accessors for seamless integration with xarray.
- Removed deprecated `grids.py` file and refactored plotting utilities.

This update enhances the plotting library, providing users with more tools for visualizing data effectively.
- QualibrationFigure plotting system with 1D/2D/multi-qubit support
- QubitGrid for custom layouts and overlay system
- Complete theming and styling with xarray accessors
- Comprehensive test suite (55 passing) and working demos
- Real data integration with ds_raw.h5 and ds_fit.h5
- Fixed styling issues and PNG export with HTML solution
- Extensive documentation and examples
- Proper handling of empty subplots for missing data
…tting

- MIGRATION_GUIDE.md: Complete step-by-step migration guide
- QUICK_REFERENCE.md: Quick reference card for common patterns
- MIGRATION_EXAMPLES.md: Real code examples from current codebase

These guides help convert from matplotlib-based plotting to the new
unified Qualibration plotting system with interactive Plotly figures,
consistent styling, and better QUAlibrate integration.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 10, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 5 committers have signed the CLA.

✅ omrieoqm
❌ Huo Chen
❌ ibarel
❌ michael-hirsch-quelements
❌ YaroslavBorysko


Huo Chen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment thread qualibration_libs/plotting/README.md Outdated
data,
x='frequency',
data_var='amplitude',
residuals=True, # Enable residuals plot
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the data corresponding to the residuals retrieved? Is it based on the name or a specific xarray attribute?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was one of the broken tests. Fix and documentation have been updated.

Residuals = data - fit_curve. Fit curve is defined in a FitOverlay, an example and notes have been added to the Readme.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be obvious, but it would be worth adding a note that residual will work only if only 1 overlay is provided and if the dataset doesn't have hue, right?

)
```

### Dynamic Overlays
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, can I use this framework to define a RefLine whose value depends on a specific qubit quam attribute?
For instance:

def overlay_func(qubit_name, qubit_data, state):
    # Generate overlays based on qubit data
    return [RefLine(x=q.xy.operations["x180"].amplitude) for q in state.qubits]

fig = qplot.QualibrationFigure.plot(
    data,
    x='frequency',
    data_var='amplitude',
    overlays=overlay_func
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michael-hirsch-quelements this is what I mentioned in the meeting regarding adding the quam state to the overlay callback function signature.

Comment thread qualibration_libs/plotting/README.md Outdated
Comment thread qualibration_libs/plotting/README.md Outdated
Comment thread qualibration_libs/plotting/README.md
Comment thread qualibration_libs/plotting/README.md
)
```

### 2D Heatmaps
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the color bars are overlapping when the figure contains multiple plots and the color scale is kind of messed up.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in the meeting, 2 options should be implemented:

  1. No colorbar is displayed (in case the range of each subplot is very different)
  2. A unique colorbar is displayed with the min and max from all the subplots (in case the range of the subplots is the same, typically 0-1, -1-+1 or 0-2)

Comment thread qualibration_libs/plotting/__init__.py
Comment on lines +240 to +248
grid = QubitGrid(
coords={
'Q0': (0, 0), # Row 0, Col 0
'Q1': (0, 1), # Row 0, Col 1
'Q2': (1, 0), # Row 1, Col 0
'Q3': (1, 1) # Row 1, Col 1
},
shape=(2, 2) # 2x2 grid
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backward compatibility reasons, and consistency with other processes, I don't think that the definition of QubitGrid should be changed. As shown in the plotting.py files, the current definition of QubitGrid should allow the implementation of a custom layout by doing:

    grid = QubitGrid(ds, [q.grid_location for q in qubits])
    for ax, qubit in grid_iter(grid):
        plot_individual_data_with_fit(ax, ds, qubit, fits.sel(qubit=qubit["qubit"]))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, QubitGrid stays unchanged. Added two optional helpers (grid_iter, make_qubit_grid_from_locations) for custom layouts and README examples, preserving backward compatibility. Will push them today

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!
I tested the latest pushed version which runs without errors, however it seems that

  • Matplotlib figures are also created
  • The layout doesn't correspond to the initial figure

We can discuss it during the meeting so that I can show you.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the Matplotlib figure: Per Huo, this is to keep backward compatibility since the original QubitGrid object will create a matplotlib figure at initialization and we are using the QubitGrid also for plotly.

And I believe you figured out the layout issue but correct me if I'm wrong.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks Michael I'll fix it internally.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheoLaudatQM I think Huo's latest PR has a fix that moves this functionality into griditer so heads up that we might need to review this together.

Comment thread qualibration_libs/plotting/README.md
ibarel and others added 30 commits October 29, 2025 12:26
- Change colorbar_tolerance from 20% to 300% in all heatmap scripts
- This ensures colorbars ALWAYS show regardless of data variation
- Perfect for testing and debugging colorbar functionality
- Will work even with extreme qubit data variations

Scripts updated:
- plot_02b_resonator_spectroscopy_vs_power_results_plotly.py
- plot_02c_resonator_spectroscopy_vs_flux_results_plotly.py
- plot_04b_power_rabi_results_plotly.py

With 300% tolerance, colorbars will show in ALL cases:
✅ Single heatmaps: 1 colorbar
✅ Multiple heatmaps: 1 colorbar (forced)
✅ Any data variation: 1 colorbar (guaranteed)
- Add testing mode for tolerance >= 2.0 (200% or higher)
- Testing mode shows colorbars on ALL subplots (not just the last one)
- Normal mode (tolerance < 2.0) still shows only 1 colorbar on last subplot
- Perfect for debugging and testing colorbar functionality

Behavior:
- tolerance >= 2.0: Show colorbars on ALL subplots (testing mode)
- tolerance < 2.0: Show 1 colorbar on last subplot (normal mode)
- tolerance >= 1.0: Force same scaling detection

With 300% tolerance in huo scripts:
✅ Each subplot gets its own colorbar
✅ Perfect for testing and debugging
✅ Easy to see individual subplot scaling
Features:
- Add with_palette decorator for temporary palette setting
- Support 24 predefined palettes (viridis, plasma, tab10, etc.)
- Support custom color lists (hex codes, named colors)
- Automatic palette restoration after function execution
- Nested decorator support (inner takes precedence)
- Thread-safe and exception-safe implementation

Fixes:
- Fix colorbar display in multiplots with heatmaps
- Show one shared colorbar when scaling is same (within tolerance)
- Hide all colorbars when scaling differs
- Proper colorbar positioning and margin adjustment
- Update HUO scripts with high tolerance for testing

Documentation:
- Add comprehensive README section for palette decorator
- Create detailed demo with 5 different examples
- Include usage examples and available palettes list

Files modified:
- qualibration_libs/plotting/config.py: Add with_palette decorator
- qualibration_libs/plotting/figure.py: Fix colorbar optimization logic
- qualibration_libs/plotting/__init__.py: Export with_palette decorator
- qualibration_libs/plotting/README.md: Add decorator documentation
- qualibration_libs/plotting/demos/palette_decorator_demo.py: New demo
- HUO scripts: Update colorbar_tolerance to 100.0 for testing
Features:
- Add with_palette_param decorator for convenient palette parameter support
- Allows passing palette as regular function parameter (palette='viridis')
- Supports all palette types: predefined names, custom colors, named colors
- Automatic palette restoration after function execution
- Works with any function signature
- More intuitive than @with_palette decorator for function calls

Usage:
- @with_palette_param decorator on plotting functions
- Pass palette as parameter: plot_data(data, palette='viridis')
- No need to create separate decorated functions
- Supports complex function signatures with multiple parameters

Documentation:
- Add comprehensive README section for parameter decorator
- Show benefits over function-level decorator
- Include usage examples and comparison

Files modified:
- qualibration_libs/plotting/config.py: Add with_palette_param decorator
- qualibration_libs/plotting/__init__.py: Export with_palette_param
- qualibration_libs/plotting/README.md: Add parameter decorator documentation
Assign distinct color palettes to each HUO script for visual variety:

- plot_02a_resonator_spectroscopy_results_plotly.py: tab10 (blue-based)
- plot_02b_resonator_spectroscopy_vs_power_results_plotly.py: set1 (red-based)
- plot_02c_resonator_spectroscopy_vs_flux_results_plotly.py: set2 (green-based)
- plot_04b_power_rabi_results_plotly.py: set3 (purple-based)

Each script now uses a different palette to make plots visually distinct:
- Blue first (tab10): Professional, scientific look
- Red first (set1): High contrast, attention-grabbing
- Green first (set2): Natural, easy on the eyes
- Purple first (set3): Creative, distinctive

This makes it easy to identify which script generated which plot at a glance.
…e-mislabeled

QWI-153: Fixed qubit labeling
…nd update documentation

Features:
- Add direct palette parameter support to QualibrationFigure.plot()
- Palette can be passed as regular parameter (no decorator needed)
- Automatically handles palette setting and restoration
- Works with all palette types (predefined names, custom colors, named colors)

Documentation:
- Expand README with comprehensive palette parameter documentation
- Add section on direct usage with QualibrationFigure.plot()
- Include all four HUO scripts as real-world examples
- Document palette choices for each HUO script (tab10, set1, set2, set3)
- Add comparison table between decorator approaches
- Include error handling and safety information
- Update plot() method docstring to document palette parameter

Technical:
- Add _set_palette_from_value() helper function
- Extract palette from style_overrides before plotting
- Temporarily set global palette during plot creation
- Restore original palette in finally block for exception safety

This makes the palette feature even more convenient - users can now pass
palette directly to QualibrationFigure.plot() without needing decorators.
…r-decorator

Feature/palette parameter decorator
…ationFigure for improved subplot layout control
…ttribute. This allows individual overlays to control their visibility in the legend, improving customization options for `RefLine`, `ScatterOverlay`, and `FitOverlay` classes.
…r-defined `showscale` settings, ensuring explicit overrides remain intact.
QWI-177: Legend for all corresponding data and fits
Add documentation of `color` and `show_legend` parameters to overlay …
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants