Skip to main content

A language for synthesizing randomized experimental designs

Project description

SweetPea

Build Status
typecheck
acceptance (fast)
acceptance (slow)
package

SweetPea is a language for declaratively specifying randomized experimental designs and synthesizing trial sequences generated from the design specification. An experimental design is a description of experimental factors, relationships between factors, sequential constraints, and how to map those factors onto a sequence of trials. Such a design is constructed by calling SweetPea functions such as fully_cross_block, factor, derived_level, and at_most_k_in_a_row.

SweetPea includes a synthesizer to generate unbiased sequences of trials that satisfy the design's constraints. In the most general case, SweetPea compiles an experimental design into a boolean formula that is passed to a SAT sampler; the SAT sampler Unigen provides statistical guarantees that the solutions it finds are approximately uniformly probable in the space of all valid solutions. Unfortunately, sampling this way is not tractable for all designs that can be expressed with SweetPea, and improving sampling strategies is a primary direction for ongoing work.

Disclaimer

While the SweetPea language (as an API) is relatively stable, its interface is still likely to evolve for now. Use with caution.

Usage

SweetPea requires Python 3.5 or later. It also depends on Docker being installed and running on your machine so that it can start a container for the backend server.

Intstall SweetPea with pip:

pip install sweetpea

Example:

import operator as op

from sweetpea import *

color = factor("color", ["red", "blue"])
text  = factor("text",  ["red", "blue"])

con_level  = derived_level("con", within_trial(op.eq, [color, text]))
inc_level  = derived_level("inc", within_trial(op.ne, [color, text]))
con_factor = factor("congruent?", [con_level, inc_level])

design       = [color, text, con_factor]
crossing     = [color, text]

k = 1
constraints = [at_most_k_in_a_row(k, (con_factor, con_level))]

block        = fully_cross_block(design, crossing, constraints)

experiments  = synthesize_trials(block)

print_experiments(block, experiments)

Additional examples can be found in the example_programs directory.

Full Documentation

See https://sweetpea-org.github.io/.

Contributing

Setup

It is recommended to prepare a virtual environment for SweetPea development. From within the sweetpea-py directory, create a new venv:

$ python3 -m venv sweetpea-py-env

Active the virtual environment:

$ source sweetpea-py-env/bin/activate

Once the virtual environment has been activated, pip install all dependencies and sweetpea-py itself:

# Dependencies
$ pip install -r requirements.txt

# SweetPea
$ pip install -e <path>/<to>/sweetpea-py

Tests

Run unit tests with make. These should only take a few seconds to finish.

$ make test

SweetPea also has a set of end to end or 'acceptance' tests to test the full integration of all components. These are also run with make:

$ make acceptance

Or:

$ make full

The acceptance tests depend on the SweetPea server. By default, the tests will start and stop the server for each test. It can be 2-3 times faster to start the server container yourself:

$ docker run --rm -d -p 8080:8080 -p 6379:6379 sweetpea/server

and then set an environment variable to tell SweetPea that you are managing the server yourself:

$ export SWEETPEA_EXTERNAL_DOCKER_MGMT=true

When that environment variable is set, SweetPea will never try to start/stop the server container, and the acceptance tests typically complete in 5-7 minutes.

Specify a Port

By default, SweetPea attempts to run its docker server using port 8080 on the host machine. If this port is not available, it can be changed by setting the SWEETPEA_DOCKER_PORT environment variable. For example, if SweetPea should instead run on port 5050,

$ export SWEETPEA_DOCKER_PORT=5050

will then change the running port to 5050.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sweetpea-0.0.42.tar.gz (78.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sweetpea-0.0.42-py3-none-any.whl (108.9 kB view details)

Uploaded Python 3

File details

Details for the file sweetpea-0.0.42.tar.gz.

File metadata

  • Download URL: sweetpea-0.0.42.tar.gz
  • Upload date:
  • Size: 78.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.10

File hashes

Hashes for sweetpea-0.0.42.tar.gz
Algorithm Hash digest
SHA256 e18db10320042c2b7f7dc7e328934672f6eb128f476416e9d60a148db34d0915
MD5 ac789b5787918d2f4cf2da664346966c
BLAKE2b-256 fb51c4b8f0b90bd3679f98852433041e66593a8e6cb599471637deb3676a1e0d

See more details on using hashes here.

File details

Details for the file sweetpea-0.0.42-py3-none-any.whl.

File metadata

  • Download URL: sweetpea-0.0.42-py3-none-any.whl
  • Upload date:
  • Size: 108.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.10

File hashes

Hashes for sweetpea-0.0.42-py3-none-any.whl
Algorithm Hash digest
SHA256 8aa75dc999c88f6f5092bffed1b7a08ed5e839024125872b1e12044095f55120
MD5 dbd490f1e70ff04aabdc516c417929aa
BLAKE2b-256 2db7174085f02178c2ff0c1520464a83530070819ebcfdb2aad6c9ded06023ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page