colmena.proxy

Utilities for interacting with ProxyStore.

Utilities for interacting with ProxyStore

exception colmena.proxy.ProxyJSONSerializationWarning

Bases: Warning

colmena.proxy.get_store(name: str, config: Dict[str, Any] | None = None) Store | None

Get a Store by name or create one if it does not already exist.

Parameters:
  • name (str) – name of the store.

  • configStore configuration that can be used to reinitialize the Store if provided and a store with name is not found.

Returns:

The store registered as name or a newly intialized and registered store if kind is not None.

colmena.proxy.proxy_json_encoder(proxy: ~<property object at 0x7f16af8c1fd0>.Proxy) Any

Custom encoder function for proxies

Proxy objects are not JSON serializable so this function, when passed to json.dumps(), will attempt to JSON serialize the wrapped object. If the proxy is not resolved, a warning will be raised for the user and the proxy will be replaced with a placeholder string for the proxy. This 1) prevents JSON serialization from failing and 2) avoid unintended resolutions of proxies that may invoke expensive communication operations without the user being aware.

Usage:
>>> # With JSON dump/dumps
>>> json.dumps(json_obj_containing_proxy, default=proxy_json_encoder)
>>> # With Pydantic
>>> my_basemodel_instance.json(encoder=proxy_json_encoder)
Parameters:

proxy (Proxy) – proxy to convert to JSON encodable object

Returns:

The object wrapped by the proxy if the proxy has already been resolved otherwise a placeholder string.

Raises:

TypeError – if proxy is not an instance of a Proxy.

colmena.proxy.resolve_proxies_async(args: object | list | tuple | dict) Proxy]

Begin asynchronously resolving all proxies in input

Scan inputs for instances of Proxy and begin asynchronously resolving. This is useful if you have one or more proxies that will be needed soon so the underlying objects can be asynchronously resolved to reduce the cost of the first access to the proxy.

Parameters:

args (object, list, tuple, dict) – possible object or iterable of objects that may be ObjectProxy instances

Returns:

List of the proxies that are being resolved

colmena.proxy.store_proxy_stats(proxy: ~<property object at 0x7f16af8c1fd0>.Proxy, proxy_timing: dict)

Store the timings associated with a proxy, if available

Parameters:
  • proxy – Proxy to evaluate

  • proxy_timing – Dictionary in which to store timings to be updated