httpstan.schemas

Module Contents

Classes

Operation

Long-running operation.

Status

Error.

CreateModelRequest

Schema for request to build a Stan program.

Model

Base schema class with which to define custom schemas.

Data

Data for a Stan model.

CreateFitRequest

Schema for request to start sampling.

Fit

Base schema class with which to define custom schemas.

ShowParamsRequest

Base schema class with which to define custom schemas.

Parameter

Schema for single parameter.

WriterMessage

Messages from callback writers and loggers in stan::callbacks.

ShowLogProbRequest

Schema for log_prob request.

ShowLogProbGradRequest

Schema for log_prob_grad request.

ShowWriteArrayRequest

Schema for write_array request.

ShowTransformInitsRequest

Schema for transform_inits request.

class httpstan.schemas.Operation(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Long-running operation.

Modeled on operations.proto, linked in https://cloud.google.com/apis/design/standard_methods

name
metadata
done
result
validate_result(self, data: dict, many: bool, partial: bool) None[source]
class httpstan.schemas.Status(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Error.

Modeled on google.rpc.Status. See https://cloud.google.com/apis/design/errors

code
status
message
details
class httpstan.schemas.CreateModelRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for request to build a Stan program.

program_code
class httpstan.schemas.Model(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Base schema class with which to define custom schemas.

Example usage:

import datetime as dt
from dataclasses import dataclass

from marshmallow import Schema, fields


@dataclass
class Album:
    title: str
    release_date: dt.date


class AlbumSchema(Schema):
    title = fields.Str()
    release_date = fields.Date()


album = Album("Beggars Banquet", dt.date(1968, 12, 6))
schema = AlbumSchema()
data = schema.dump(album)
data  # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'}
Parameters
  • only – Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters.

  • exclude – Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only and exclude, it is not used. Nested fields can be represented with dot delimiters.

  • many – Should be set to True if obj is a collection so that the object will be serialized to a list.

  • context – Optional context passed to fields.Method and fields.Function fields.

  • load_only – Fields to skip during serialization (write-only fields)

  • dump_only – Fields to skip during deserialization (read-only fields)

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

Changed in version 3.0.0: prefix parameter removed.

Changed in version 2.0.0: __validators__, __preprocessors__, and __data_handlers__ are removed in favor of marshmallow.decorators.validates_schema, marshmallow.decorators.pre_load and marshmallow.decorators.post_dump. __accessor__ and __error_handler__ are deprecated. Implement the handle_error and get_attribute methods instead.

name
compiler_output
stanc_warnings
class httpstan.schemas.Data(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Data for a Stan model.

class Meta[source]
unknown
validate_stan_values(self, data: dict, many: bool, partial: bool) None[source]

Verify data dictionary will work for Stan.

Keys should be strings, values must be numbers or (nested) lists of numbers.

class httpstan.schemas.CreateFitRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for request to start sampling.

Only two algorithms are supported: hmc_nuts_diag_e_adapt and fixed_param.

Sampler parameters can be found in httpstan/stan_services.cpp.

function
data
init
random_seed
chain
init_radius
num_warmup
num_samples
num_thin
save_warmup
refresh
stepsize
stepsize_jitter
max_depth
delta
gamma
kappa
t0
init_buffer
term_buffer
window
class httpstan.schemas.Fit(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Base schema class with which to define custom schemas.

Example usage:

import datetime as dt
from dataclasses import dataclass

from marshmallow import Schema, fields


@dataclass
class Album:
    title: str
    release_date: dt.date


class AlbumSchema(Schema):
    title = fields.Str()
    release_date = fields.Date()


album = Album("Beggars Banquet", dt.date(1968, 12, 6))
schema = AlbumSchema()
data = schema.dump(album)
data  # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'}
Parameters
  • only – Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters.

  • exclude – Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only and exclude, it is not used. Nested fields can be represented with dot delimiters.

  • many – Should be set to True if obj is a collection so that the object will be serialized to a list.

  • context – Optional context passed to fields.Method and fields.Function fields.

  • load_only – Fields to skip during serialization (write-only fields)

  • dump_only – Fields to skip during deserialization (read-only fields)

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

Changed in version 3.0.0: prefix parameter removed.

Changed in version 2.0.0: __validators__, __preprocessors__, and __data_handlers__ are removed in favor of marshmallow.decorators.validates_schema, marshmallow.decorators.pre_load and marshmallow.decorators.post_dump. __accessor__ and __error_handler__ are deprecated. Implement the handle_error and get_attribute methods instead.

name
class httpstan.schemas.ShowParamsRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Base schema class with which to define custom schemas.

Example usage:

import datetime as dt
from dataclasses import dataclass

from marshmallow import Schema, fields


@dataclass
class Album:
    title: str
    release_date: dt.date


class AlbumSchema(Schema):
    title = fields.Str()
    release_date = fields.Date()


album = Album("Beggars Banquet", dt.date(1968, 12, 6))
schema = AlbumSchema()
data = schema.dump(album)
data  # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'}
Parameters
  • only – Whitelist of the declared fields to select when instantiating the Schema. If None, all fields are used. Nested fields can be represented with dot delimiters.

  • exclude – Blacklist of the declared fields to exclude when instantiating the Schema. If a field appears in both only and exclude, it is not used. Nested fields can be represented with dot delimiters.

  • many – Should be set to True if obj is a collection so that the object will be serialized to a list.

  • context – Optional context passed to fields.Method and fields.Function fields.

  • load_only – Fields to skip during serialization (write-only fields)

  • dump_only – Fields to skip during deserialization (read-only fields)

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

Changed in version 3.0.0: prefix parameter removed.

Changed in version 2.0.0: __validators__, __preprocessors__, and __data_handlers__ are removed in favor of marshmallow.decorators.validates_schema, marshmallow.decorators.pre_load and marshmallow.decorators.post_dump. __accessor__ and __error_handler__ are deprecated. Implement the handle_error and get_attribute methods instead.

data
class httpstan.schemas.Parameter(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for single parameter.

name
dims
constrained_names
class httpstan.schemas.WriterMessage(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Messages from callback writers and loggers in stan::callbacks.

NOTE: You SHOULD NOT use this schema. This schema exists for testing and for documentation. It SHOULD NOT be used to process a large number of JSON messages. Doing so will slow down any program.

This schema is intended for messages emitted by C++ classes which inherit from

  • stan/callbacks/writer.hpp, and

  • stan/callbacks/logger.hpp.

In particular, the schema matches a JSON-based “version” of the CSV-focused stan/callbacks/stream_writer.hpp and stan/callbacks/stream_logger.hpp.

This version is found “inside” the httpstan-specific httpstan/socket_writer.hpp and httpstan/socket_logger.hpp.

WriterMessage is a data format for all messages written by the callback writers defined in stan::callbacks. These writers are used by the functions defined in stan::services. For example, stan::services::sample::hmc_nuts_diag_e uses one logger and three writers:

  • logger Logger for informational and error messages

  • init_writer Writer callback for unconstrained inits

  • sample_writer Writer for draws

  • diagnostic_writer Writer for diagnostic information

WriterMessage is a format which is flexible enough to accommodate these different uses while still providing a predictable structure.

A WriterMessage has a field topic which provides information about what the WriterMessage concerns or what produced it. For example, the topic associated with a WriterMessage written by sample_writer in the function is sample.

The “content” of a message is stored in the field values. This is either a list or a mapping.

version
topic
values
class httpstan.schemas.ShowLogProbRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for log_prob request.

data
unconstrained_parameters
adjust_transform
class httpstan.schemas.ShowLogProbGradRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for log_prob_grad request.

data
unconstrained_parameters
adjust_transform
class httpstan.schemas.ShowWriteArrayRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for write_array request.

data
unconstrained_parameters
include_tparams
include_gqs
class httpstan.schemas.ShowTransformInitsRequest(*, only: types.StrSequenceOrSet | None = None, exclude: marshmallow.types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: marshmallow.types.StrSequenceOrSet = (), dump_only: marshmallow.types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet | None = None, unknown: str | None = None)[source]

Bases: marshmallow.Schema

Schema for transform_inits request.

data
constrained_parameters