api - Web application interface¶
Call an async function inside the active loop, reporting any exceptions on the logger. |
|
Get the convergence plot for the current fit state. |
|
List Windows drive roots, e.g. ["C:", "D:"]; empty on other platforms. |
|
Load the problem from json or from a script file. |
|
Fix v to a value with a given number of digits of precision |
|
Decorator to register a function as a download endpoint with a specific mimetype. |
|
Export current problem to a file. |
|
Set the fit problem. |
|
Set the fit problem from a saved problem state. |
|
Set the session output file to be used for saving results, and enable autosave. |
|
Set the trim portion for the current fit state. |
|
Trigger the abort fit signal to the optimizer and wait for complete (or not). |
|
Update the current FitProblem without resetting the fit state. |
|
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)
- 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]
- async bumps.api.add_notification(content: str, title: str = 'Notification', timeout: int | None = None)[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.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_topic_messages(topic: Literal['log'] | None = None, max_num=None) List[Dict][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:].
- 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.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.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_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.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_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_problemwhen 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.solvedetects the label mismatch and rebuilds the chain state via_rebuild_mcmc_statebefore 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 asset_serialized_problem.