api - Web application interface

Emitter

ParamInfo

WebviewPlotFunction

add_notification

apply_parameters

call_async

Call an async function inside the active loop, reporting any exceptions on the logger.

create_custom_plot

emit

export_fit

export_results

fit_complete_handler

fit_progress_handler

get_chisq

get_convergence_plot

Get the convergence plot for the current fit state.

get_correlation_plot

get_custom_plot

get_custom_plot_info

get_data_plot

get_dirlisting

get_fit_fields

get_fitter_defaults

get_history

get_model

get_model_names

get_model_uncertainty_plot

get_parameter_labels

get_parameter_trace_plot

get_parameters

get_running_loop

get_serializer

get_session

get_shared_setting

get_topic_messages

get_uncertainty_plot

listdrives

List Windows drive roots, e.g. ["C:", "D:"]; empty on other platforms.

load_problem_file

Load the problem from json or from a script file.

load_session

log

nice

Fix v to a value with a given number of digits of precision

notify_shared_setting

now_string

params_to_list

publish

register

register_download

Decorator to register a function as a download endpoint with a specific mimetype.

reload_history_item

remove_history_item

save_parameters

save_problem_file

Export current problem to a file.

save_session

save_session_copy

save_to_history

set_fit_options

set_fit_result

set_keep_history

set_parameter

set_problem

Set the fit problem.

set_serialized_problem

Set the fit problem from a saved problem state.

set_session_output_file

Set the session output file to be used for saving results, and enable autosave.

set_shared_setting

set_trim_portion

Set the trim portion for the current fit state.

shake_parameters

shutdown

start_fit

start_fit_thread

stop_fit

Trigger the abort fit signal to the optimizer and wait for complete (or not).

to_json_compatible_dict

update_history_label

update_serialized_problem

Update the current FitProblem without resetting the fit state.

wait_for_fit_complete

Python api for controlling webview.

These are mostly called by webview and by the command line startup script. They are not particularly useful from a jupyter notebook.

import bumps.names as bp

# Start the bumps server and run it in the background await bp.start_bumps()

# Display webview in a jupyter cell display_bumps(height=600)

# Load a model script, possibly with additional command line arguments: path = Path(“path/to/model.py”) problem = bp.load_problem(path, args=[arg1, …])

# Use a problem defined in a separate jupyter cell await bp.set_problem(problem, new_model=False)

class bumps.api.Emitter(*args, **kwargs)[source]

Bases: Protocol

bumps.api.JSON_TYPE

Type union of a JSON compatible python structure

alias of str | float | bool | None | Sequence[JSON_TYPE] | Mapping[str, JSON_TYPE]

class bumps.api.ParamInfo[source]

Bases: TypedDict

fittable: bool
fixed: bool
id: str
max_str: str
min_str: str
name: str
paths: List[str]
slot_repr: str
tags: List[str]
value01: float
value_str: str
writable: bool
class bumps.api.WebviewPlotFunction(*args, **kwargs)[source]

Bases: Protocol

async bumps.api.add_notification(content: str, title: str = 'Notification', timeout: int | None = None)[source]
async bumps.api.apply_parameters(pathlist: List[str], filename: str)[source]
bumps.api.call_async(async_fn, *args, **kw)[source]

Call an async function inside the active loop, reporting any exceptions on the logger.

async bumps.api.create_custom_plot(model_index: int, plot_title: str, n_samples: int = 1) CustomWebviewPlot[source]
async bumps.api.emit(event: str, data: Any | None = None, to: str | None = None, room: str | None = None, skip_sid: str | None = None, namespace: str | None = None, callback: Callable | None = None, ignore_queue: bool = False)[source]
bumps.api.export_fit(path: Path | str, problem: FitProblem, fit: FitResult | OptimizeResult, serializer: str | None = 'dataclass', basename: str | None = None)[source]
async bumps.api.export_results(export_path: str | List[str] = '')[source]
bumps.api.fit_complete_handler(event: Dict)[source]
bumps.api.fit_progress_handler(event: Dict)[source]
async bumps.api.get_chisq(problem: FitProblem | None = None, nllf=None) str[source]
async bumps.api.get_convergence_plot(cutoff: float = 0.25, portion: float | None = None, max_points: int | None = 10000)[source]

Get the convergence plot for the current fit state. If the fit state is not available, return None. If the convergence is not available, return None.

Parameters:
  • cutoff – The cutoff value for the convergence plot (fraction of points below this value are not shown)

  • max_points – The maximum number of points to plot (thinning applied if too many points)

Returns:

A JSON-serializable dictionary containing the convergence plot data.

async bumps.api.get_correlation_plot(sort: bool = True, max_rows: int = 8, nbins: int = 50, vars=None, timestamp: str = '')[source]
async bumps.api.get_custom_plot(model_index: int, plot_title: str, n_samples: int = 1)[source]
async bumps.api.get_custom_plot_info()[source]
async bumps.api.get_data_plot(model_indices: List[int] | None = None)[source]
async bumps.api.get_dirlisting(pathlist: List[str] | None = None)[source]
async bumps.api.get_fit_fields()[source]
async bumps.api.get_fitter_defaults()[source]
async bumps.api.get_history()[source]
async bumps.api.get_model()[source]
async bumps.api.get_model_names()[source]
async bumps.api.get_model_uncertainty_plot()[source]
async bumps.api.get_parameter_labels()[source]
async bumps.api.get_parameter_trace_plot(var: int)[source]
async bumps.api.get_parameters(only_fittable: bool = False)[source]
bumps.api.get_running_loop()[source]
async bumps.api.get_serializer()[source]
async bumps.api.get_session()[source]
async bumps.api.get_shared_setting(setting: str)[source]
async bumps.api.get_topic_messages(topic: Literal['log'] | None = None, max_num=None) List[Dict][source]
async bumps.api.get_uncertainty_plot(timestamp: str = '')[source]
bumps.api.listdrives() list[str][source]

List Windows drive roots, e.g. [“C:", “D:"]; empty on other platforms.

async bumps.api.load_problem_file(pathlist: List[str], filename: str, autosave_previous: bool = True, args: List[str] = None)[source]

Load the problem from json or from a script file.

pathlist is a list of folder components and filename is the script file in that folder. These are joined together as “Path(pathlist, filename)” to build the complete path. If path is already a Path to the file, use *load_problem_file([path.parent], path.name, …)

If autosave_previous then store the current problem state in the session file before loading the new problem (default=True).

args are any additional arguments to the script file. This will be available in the script as sys.argv[1:].

async bumps.api.load_session(pathlist: List[str], filename: str, read_only: bool = False)[source]
async bumps.api.log(message: str, title: str | None = None)[source]
bumps.api.nice(v, digits=4)[source]

Fix v to a value with a given number of digits of precision

async bumps.api.notify_shared_setting(setting: str, value: Any)[source]
bumps.api.now_string()[source]
bumps.api.params_to_list(params, lookup=None, path='', freevars=None) List[ParamInfo][source]
async bumps.api.publish(topic: str, message: Any = None)[source]
bumps.api.register(fn: Callable)[source]
bumps.api.register_download(mimetype: str = 'application/octet-stream', filename: str = 'result.dat')[source]

Decorator to register a function as a download endpoint with a specific mimetype.

async bumps.api.reload_history_item(name: str)[source]
async bumps.api.remove_history_item(name: str)[source]
async bumps.api.save_parameters(pathlist: List[str], filename: str, overwrite: bool = False)[source]
async bumps.api.save_problem_file(pathlist: List[str] | None = None, filename: str | None = None, overwrite: bool = False)[source]

Export current problem to a file.

pathlist and file

async bumps.api.save_session()[source]
async bumps.api.save_session_copy(pathlist: List[str], filename: str)[source]
async bumps.api.save_to_history(label: str, keep: bool = False) str[source]
async bumps.api.set_fit_options(fitter_id: str, options: Dict[str, Any])[source]
async bumps.api.set_fit_result(fit_result: FitResult)[source]
async bumps.api.set_keep_history(name: str, keep: bool)[source]
async bumps.api.set_parameter(parameter_id: str, property: Literal['value01', 'value', 'min', 'max'], value: float | str | bool)[source]
async bumps.api.set_problem(problem: FitProblem, path: Path | None = None, filename: str = '', new_model: bool = True, name: str | None = None, autosave_previous: bool = True, fit: OptimizeResult | None = None)[source]

Set the fit problem.

problem is a fitting problem defined in a jupyter cell.

path and filename give the nominal location of the problem on disk. These are displayed in webview and stored in the session file, but not actually used to load the problem.

new_model is True if the problem should be saved to the session file as “Loaded model” (default True)

name is an optional override for the model name.

async bumps.api.set_serialized_problem(serialized, new_model: bool = False, name: str | None = None, method: str = 'dataclass')[source]

Set the fit problem from a saved problem state.

serialized is the serialized fit problem. method is the method used for serialization.

If new_model is True, then save the model to history with tag “Loaded model”. (default=False)

name is an optional override for the model name.

For example:

await set_serialized_problem(api.state.problem.fitProblem, method=api.state.problem.serializer)
async bumps.api.set_session_output_file(filepath: str | Path | None = None)[source]

Set the session output file to be used for saving results, and enable autosave. If filepath is None, the session output file is cleared and autosave is disabled.

async bumps.api.set_shared_setting(setting: str, value: Any)[source]
async bumps.api.set_trim_portion(portion: float)[source]

Set the trim portion for the current fit state. This will update the trim index and burn index in the fit state.

async bumps.api.shake_parameters()[source]
async bumps.api.shutdown()[source]
async bumps.api.start_fit(options)[source]
async bumps.api.start_fit_thread(fitter_id: str | None = None, options: Dict[str, Any] | None = None, resume: bool = False)[source]
async bumps.api.stop_fit(wait=True)[source]

Trigger the abort fit signal to the optimizer and wait for complete (or not).

bumps.api.to_json_compatible_dict(obj) str | float | bool | None | Sequence[str | float | bool | None | Sequence[JSON_TYPE] | Mapping[str, JSON_TYPE]] | Mapping[str, str | float | bool | None | Sequence[JSON_TYPE] | Mapping[str, JSON_TYPE]][source]
async bumps.api.update_history_label(name: str, label: str)[source]
async bumps.api.update_serialized_problem(serialized: str, method: str = 'dataclass', name: str | None = None)[source]

Update the current FitProblem without resetting the fit state.

Use this instead of set_serialized_problem when you want to resume DREAM from the existing chain population rather than starting fresh.

Parameter-space changes (parameters added, removed, or renamed) are handled automatically on the next start_fit_thread("dream", options, resume=True) call: DreamFit.solve detects the label mismatch and rebuilds the chain state via _rebuild_mcmc_state before sampling begins.

Use set_serialized_problem() for a true cold start.

The method parameter accepts "dataclass" (default, safe), "pickle", "cloudpickle", or "dill". The latter three enable arbitrary code execution and carry the same caveat as set_serialized_problem.

async bumps.api.wait_for_fit_complete()[source]