pulsatrix 1.1.0
Loading...
Searching...
No Matches
mime_bundle.hpp File Reference

Rich notebook display: mime_bundle_repr() for pulsatrix's types (roadmap NB-1). More...

#include <cstdint>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "pulsatrix/json.hpp"
#include "pulsatrix/performance.hpp"
#include "pulsatrix/viz/document.hpp"
#include "pulsatrix/viz/protein_documents.hpp"
#include "pulsatrix/viz/series.hpp"
#include "pulsatrix/viz/topology_documents.hpp"
Include dependency graph for mime_bundle.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pulsatrix::MimeBundle
 One displayable value in several formats: MIME type to data, richest first. Text formats (text/plain, text/html, image/svg+xml, base64 image/png) are strings; +json formats are JSON objects, as Jupyter's display protocol and nbformat store them. More...
 

Namespaces

namespace  pulsatrix
 

Functions

JsonValue pulsatrix::ToVegaLiteCircuitGraph (const CircuitGraphDocument &doc)
 A Vega-Lite node-link view of a circuit graph: nodes in columns by depth (longest path from a source), colored by ablation effect, edges as lines weighted by |weight|.
 
std::string pulsatrix::Base64Encode (const std::vector< uint8_t > &bytes)
 Standard base64 (RFC 4648, with padding), for image/png data.
 
template<class Json >
void pulsatrix::to_json (Json &j, const JsonValue &value)
 Converts a JsonValue to another JSON library's value type by its common interface (assignment from null, bool, number and string; object(), array(), operator[], push_back). nlohmann::json finds it by argument-dependent lookup, so nlohmann::json j = value; works without pulsatrix including nlohmann.
 
template<class Json >
void pulsatrix::to_json (Json &j, const MimeBundle &bundle)
 The bundle as a JSON object of MIME type to data (see to_json(Json&, const JsonValue&)).
 
mime_bundle_repr

What a notebook shows for each type. Every bundle has text/plain.

xeus-cpp's xcpp::display(x) calls mime_bundle_repr(x) unqualified, so argument-dependent lookup finds these overloads, and the result converts to xeus's nlohmann::json through to_json() below; pulsatrix itself doesn't depend on xeus or on nlohmann. NB-2's notebook writer and NB-3's Python _repr_mimebundle_ use the same bundles.

  • Tensor: a summary (shape, device, statistics, leading values) as text and an HTML table.
  • Attribution: rank 3 or more, read as (N, H, W) or (N, C, H, W), as a heatmap of the first example with channels summed: PNG when it has more than 64 x 64 cells, SVG plus Vega-Lite otherwise. Rank 1 or 2 as a bar chart of the first example's largest features.
  • Documents with a Vega-Lite view get Vega-Lite and the SVG figure; token relevance and the protein views get their SVG; circuit graphs and training logs get Vega-Lite only.
MimeBundle pulsatrix::mime_bundle_repr (const Tensor &tensor)
 
MimeBundle pulsatrix::mime_bundle_repr (const Attribution &attribution)
 
MimeBundle pulsatrix::mime_bundle_repr (const CircuitGraph &graph)
 
MimeBundle pulsatrix::mime_bundle_repr (const AttributionDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const HeatmapDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const TokenRelevanceDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const CircuitGraphDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const TrainingLogDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const PartialDependenceDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const SensitivityDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const CounterfactualDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const MorrisDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const SobolDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const ProjectionDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const MutationMapDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const SequenceLogoDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const ContactMapDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const ResidueTracksDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const PersistenceDiagramDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const SeriesDocument &doc)
 
MimeBundle pulsatrix::mime_bundle_repr (const ClassificationReport &report)
 
MimeBundle pulsatrix::mime_bundle_repr (const SliceErrorReport &report)
 

Variables

constexpr const char * pulsatrix::kVegaLiteMimeType = "application/vnd.vegalite.v5+json"
 The MIME type Jupyter front ends (JupyterLab, Notebook 7, VS Code) render Vega-Lite from. pulsatrix's specs use only Vega-Lite 5 features, so they're sent as version 5.
 

Detailed Description

Rich notebook display: mime_bundle_repr() for pulsatrix's types (roadmap NB-1).