state - Manage bumps server state and session files

ActiveFit

Information about the currently active fit.

CustomPlotsAvailable

Whether or not the current model has custom plots.

FileInfo

Webview client treats a path as a filename plus a list of leading folder names.

FitResult

Stores the result of a fit operation.

History

Manages the history of fit results.

HistoryItem

Represents a single item in the fit history.

ProblemState

Stores the state of a Bumps fit problem.

SharedState

Server state that automatically synchronizes with the attached clients.

State

Manage the state for a bumps server session.

StringAttribute

Timestamp

ISO8601 time string

UNDEFINED

Singleton value which is undefined.

UNDEFINED_TYPE

Type for the UNDEFINED singleton.

UncertaintyAvailable

Whether or not the fit results contain MCMC samples.

deserialize_problem

deserialize_problem_bytes

get_custom_plots_available

now_string

read_bytes

read_fitproblem

read_json

read_ndarray

read_string

read_version

serialize_problem

serialize_problem_bytes

write_bytes

write_fitproblem

write_json

write_ndarray

write_string

write_version

Manage bumps server state and session files.

class bumps.state.ActiveFit[source]

Bases: TypedDict

Information about the currently active fit. This is used to share information between the webview client and the server.

chisq: str
fitter_id: str
num_steps: int
options: Dict[str, Any]
step: int
value: float
class bumps.state.CustomPlotsAvailable[source]

Bases: TypedDict

Whether or not the current model has custom plots.

If parameter_based is True then new plots need to be generated whenever the parameter values are updated.

If uncertainty_based is True then new plots need to be generated whenever the MCMC sample is updated.

parameter_based: bool
uncertainty_based: bool
class bumps.state.FileInfo[source]

Bases: TypedDict

Webview client treats a path as a filename plus a list of leading folder names.

filename: str
pathlist: List[str]
class bumps.state.FitResult(method: str = 'amoeba', options: Dict[str, ~typing.Any]=<factory>, convergence: List | None = None, fit_state: Any = None)[source]

Bases: object

Stores the result of a fit operation.

Attributes:

method: The fitting method used.

options: Options used to run the fitters.

convergence: List of quantiles for each fit iteration.

fit_state: Fit state for resume, and for sampling from Monte Carlo fitters.

convergence: List | None = None

List of best or (best, min, -1sigma, median, +1sigma, max) for the population at each step of the fit.

fit_state: Any = None

Fit state for resume, and for sampling from Monte Carlo fitters.

method: str = 'amoeba'

Fitting method

options: Dict[str, Any]

Options used to run the fitters

read(parent: Group)[source]

Read the fit result from an HDF5 group.

Args:

parent: The parent HDF5 group containing the entries.

write(parent: Group, include_fit_state=True)[source]

Write the fit result to an HDF5 group.

Args:

parent: The parent HDF5 group.

include_fit_state: Whether to include the fit state in the output.

class bumps.state.History[source]

Bases: object

Manages the history of fit results.

Attributes:

store: A dictionary mapping history item names to HistoryItem instances.

add_item(item: HistoryItem, target_length: int)[source]

Add a new history item to the history.

Args:

item: The history item to add.

target_length: The maximum length of the history.

Returns:

The name of the added history item.

get_item(name: str | UNDEFINED_TYPE | None, default=None)[source]

Get a history item by name.

Args:

name: The name of the history item.

default: The default value to return if the item is not found.

Returns:

The history item, or the default value if not found.

list()[source]

List the history items.

Returns:

A list of dictionaries containing information about each history item.

prune(target_length: int)[source]

Prune the history to a target length.

Args:

target_length: The desired length of the history.

read(parent: Group)[source]

Read the history from an HDF5 group.

Args:

parent: The parent HDF5 group.

remove_item(name: str)[source]

Remove a history item by name.

Args:

name: The name of the history item to remove.

set_keep(name: str, keep: bool)[source]

Set whether to keep a history item.

Args:

name: The name of the history item.

keep: Whether to keep the history item.

store: Dict[str, HistoryItem]
update_label(name: str, label: str)[source]

Update the label of a history item.

Args:

name: The name of the history item.

label: The new label for the history item.

write(parent: Group, include_fit_state=True)[source]

Write the history to an HDF5 group.

Args:

parent: The parent HDF5 group.

include_fit_state: Whether to include the fit state in the history.

class bumps.state.HistoryItem[source]

Bases: object

Represents a single item in the fit history.

Attributes:

problem: The problem state at this point in history.

fitting: The fit result associated with this history item.

timestamp: The timestamp when this history item was created.

label: A label for this history item.

chisq_str: A string representation of the chi-squared value.

keep: Whether to permanently keep this history item, or drop it when too many history items are saved.

chisq_str: str
fitting: FitResult | None
keep: bool
label: str
problem: ProblemState
timestamp: str
class bumps.state.ProblemState(fitProblem: bumps.fitproblem.FitProblem | None = None, serializer: Literal['dataclass', 'pickle', 'cloudpickle', 'dill'] | None = None)[source]

Bases: object

Stores the state of a Bumps fit problem.

Attributes:

fitProblem: The Bumps fit problem instance.

serializer: The serialization method to use.

fitProblem: bumps.fitproblem.FitProblem | None = None
read(parent: Group)[source]

Read the problem state from an HDF5 group.

Args:

parent: The parent HDF5 group.

serializer: Literal['dataclass', 'pickle', 'cloudpickle', 'dill'] | None = None
write(parent: Group)[source]

Write the problem state to an HDF5 group.

Args:

parent: The parent HDF5 group.

class bumps.state.SharedState(updated_convergence: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.Timestamp = UNDEFINED_TYPE(), updated_uncertainty: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.Timestamp = UNDEFINED_TYPE(), updated_parameters: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.Timestamp = UNDEFINED_TYPE(), updated_model: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.Timestamp = UNDEFINED_TYPE(), updated_history: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.Timestamp = UNDEFINED_TYPE(), selected_fitter: ~bumps.state.UNDEFINED_TYPE | str = 'amoeba', fitter_settings: ~bumps.state.UNDEFINED_TYPE | ~typing.Dict[str, ~typing.Dict] = UNDEFINED_TYPE(), active_fit: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.ActiveFit = UNDEFINED_TYPE(), model_file: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.FileInfo = UNDEFINED_TYPE(), model_loaded: ~bumps.state.UNDEFINED_TYPE | bool = UNDEFINED_TYPE(), session_output_file: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.FileInfo = UNDEFINED_TYPE(), autosave_session: bool = False, autosave_session_interval: int = 300, autosave_history: bool = True, autosave_history_length: int = 10, uncertainty_available: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.UncertaintyAvailable = UNDEFINED_TYPE(), convergence_available: ~bumps.state.UNDEFINED_TYPE | bool = UNDEFINED_TYPE(), resumable: ~bumps.state.UNDEFINED_TYPE | str | None = None, custom_plots_available: ~bumps.state.UNDEFINED_TYPE | ~bumps.state.CustomPlotsAvailable = UNDEFINED_TYPE(), active_history: ~bumps.state.UNDEFINED_TYPE | str | None = UNDEFINED_TYPE(), _notification_callbacks: ~typing.Dict[str, ~typing.Callable[[str, ~typing.Any], ~typing.Awaitable[None]]] = <factory>)[source]

Bases: object

Server state that automatically synchronizes with the attached clients.

active_fit: UNDEFINED_TYPE | ActiveFit = UNDEFINED_TYPE()
active_history: UNDEFINED_TYPE | str | None = UNDEFINED_TYPE()
autosave_history: bool = True
autosave_history_length: int = 10
autosave_session: bool = False
autosave_session_interval: int = 300
convergence_available: UNDEFINED_TYPE | bool = UNDEFINED_TYPE()
custom_plots_available: UNDEFINED_TYPE | CustomPlotsAvailable = UNDEFINED_TYPE()
fitter_settings: UNDEFINED_TYPE | Dict[str, Dict] = UNDEFINED_TYPE()
async get(name)[source]
model_file: UNDEFINED_TYPE | FileInfo = UNDEFINED_TYPE()
model_loaded: UNDEFINED_TYPE | bool = UNDEFINED_TYPE()
async notify(name, value=None)[source]
read(parent: Group)[source]
resumable: UNDEFINED_TYPE | str | None = None
selected_fitter: UNDEFINED_TYPE | str = 'amoeba'
session_output_file: UNDEFINED_TYPE | FileInfo = UNDEFINED_TYPE()
async set(name, value)[source]
uncertainty_available: UNDEFINED_TYPE | UncertaintyAvailable = UNDEFINED_TYPE()
updated_convergence: UNDEFINED_TYPE | Timestamp = UNDEFINED_TYPE()
updated_history: UNDEFINED_TYPE | Timestamp = UNDEFINED_TYPE()
updated_model: UNDEFINED_TYPE | Timestamp = UNDEFINED_TYPE()
updated_parameters: UNDEFINED_TYPE | Timestamp = UNDEFINED_TYPE()
updated_uncertainty: UNDEFINED_TYPE | Timestamp = UNDEFINED_TYPE()
write(parent: Group)[source]
class bumps.state.State[source]

Bases: object

Manage the state for a bumps server session.

There is a primary state object for the current webview instance defined in bumps.api. Temporary state objects are created to save the temporary fit results as a session file.

app_name: str = 'bumps'
app_version: str = '1.0.5.post24+g5c334ab'
async async_cleanup()[source]
autosave()[source]
base_path: str = ''
calling_loop: AbstractEventLoop | None = None
cleanup()[source]
client_path: Path = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/bumps/checkouts/latest/bumps/webview/client')
console_update_interval: int = 0
fit_abort_event: Event

Cleared before the fit and set on Stop button or Ctrl-C to end the fit.

fit_complete_event: Event

Cleared before the fit starts and set when the fit is complete and saved.

fit_thread: FitThread | None = None
fitting: FitResult
get_history()[source]
get_last_message(topic: Literal['log'])[source]
get_session_bytes() bytes[source]
get_session_bytestring() str[source]
history: History
hostname: str
mapper: BaseMapper | None = None
parallel: int = 0
port: int
problem: ProblemState
read_fitstate_from_session(session_fullpath: str)[source]
read_problem_from_session(session_fullpath: str)[source]
read_session_bytestring(session_bytestring: str, read_problem: bool = True, read_fitstate: bool = True)[source]
read_session_file(session_fullpath: str, read_problem: bool = True, read_fitstate: bool = True)[source]
read_topics(parent: Group)[source]
reload_history_item(name: str)[source]
remove_history_item(name: str)[source]
reset_fitstate(copy: bool = False)[source]

Unlink the fitting state from a history item.

This action occurs when fitProblem object is modified so that it is no longer compatible with fit results.

save()[source]
save_to_history(label: str, keep: bool = False) str[source]
set_active(problem, fitting: FitResult | None = None)[source]
set_convergence(convergence)[source]
set_fit_state(fit_state, method=None)[source]
setup_backing(session_file_name: str, session_pathlist: List[str], read_only: bool = False)[source]
shared: SharedState
shutdown_on_fit_complete: bool = False

Used to implement the –exit option to halt server on completion.

topics: Dict[Literal['log'], deque[dict]]
write_session_file(session_fullpath: str)[source]
write_topics(parent: Group)[source]
class bumps.state.StringAttribute[source]

Bases: object

classmethod deserialize(obj=None)[source]
classmethod serialize(obj=None)[source]
class bumps.state.Timestamp

ISO8601 time string

alias of str

bumps.state.UNDEFINED = UNDEFINED_TYPE()

Singleton value which is undefined. This is different from a value which is present but None.”

class bumps.state.UNDEFINED_TYPE[source]

Bases: object

Type for the UNDEFINED singleton.

class bumps.state.UncertaintyAvailable[source]

Bases: TypedDict

Whether or not the fit results contain MCMC samples.

available: bool
num_points: int
bumps.state.deserialize_problem(serialized: str, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill']) bumps.fitproblem.FitProblem[source]
bumps.state.deserialize_problem_bytes(serialized: bytes, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill']) bumps.fitproblem.FitProblem[source]
bumps.state.get_custom_plots_available(problem: bumps.fitproblem.FitProblem)[source]
bumps.state.now_string()[source]
bumps.state.read_bytes(group: Group, name: str)[source]
bumps.state.read_fitproblem(group: Group, name: str, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill']) bumps.fitproblem.FitProblem[source]
bumps.state.read_json(group: Group, name: str)[source]
bumps.state.read_ndarray(group: Group, name: str)[source]
bumps.state.read_string(group: Group, name: str)[source]
bumps.state.read_version(group: Group)[source]
bumps.state.serialize_problem(problem: bumps.fitproblem.FitProblem, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill'] | None = None) str | bytes[source]
bumps.state.serialize_problem_bytes(problem: bumps.fitproblem.FitProblem, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill']) bytes[source]
bumps.state.write_bytes(group: Group, name: str, data: bytes)[source]
bumps.state.write_fitproblem(group: Group, name: str, fitProblem: bumps.fitproblem.FitProblem, method: Literal['dataclass', 'pickle', 'cloudpickle', 'dill'])[source]
bumps.state.write_json(group: Group, name: str, data)[source]
bumps.state.write_ndarray(group: Group, name: str, data: ndarray[tuple[Any, ...], dtype[_ScalarT]] | None)[source]
bumps.state.write_string(group: Group, name: str, data: str, encoding='utf-8')[source]
bumps.state.write_version(group: Group, version: Tuple[int])[source]