Papers
Topics
Authors
Recent
Search
2000 character limit reached

Goxpyriment: A Go Framework for Behavioral and Cognitive Experiments

Published 16 Apr 2026 in q-bio.NC | (2604.15245v1)

Abstract: We introduce `Goxpyriment', a new open-source software framework for programming behavioral and cognitive experiments using the Go programming language. The library is designed to address some limitations of existing Python-based experiment tools, particularly the runtime environment complexity that frequently complicates deployment across laboratories. Because Go is a compiled language that can natively embed assets (e.g., graphics, audio files, and stimulus lists), Goxpyriment compiles entire experiments into single, self-contained executable binaries with zero runtime dependencies. This drastically simplifies distribution to collaborators and testing computers. The programming interface, inspired by Expyriment (Krause & Lindemann, 2014), was designed to be human friendly. The library includes an array of visual stimuli (text, shapes, images, Gabor patches, motion clouds, ...) and audio capabilities (WAV playback and tone generation). While developing Goxpyriment, we focused on timing reliability. Input events are timestamped by the operating system at hardware-interrupt time, so reaction times are computed by subtracting two OS-level timestamps rather than relying on continuous polling. Go's garbage collector can be disabled, greatly reducing the probability of unpredictable pauses that could corrupt stimulus timing. Finally, a set of over forty psychology experiments implemented in Goxpyriment are provided that promote not only learning by humans but also improve the ability of modern AI-assisted coding tools to help program experiments. The framework is released under the GNU General Public License v3 and is freely available at https://github.com/chrplr/goxpyriment.

Summary

  • The paper introduces a novel Go-based framework that ensures high-precision stimulus timing and zero runtime dependencies for cognitive experiments.
  • It leverages explicit garbage collection control and robust hardware synchronization to enhance stimulus presentation and accurate response measurement.
  • Empirical tests on a Raspberry Pi 4 demonstrate sub-millisecond visual and audio precision, bolstering reproducible cross-lab experimental setups.

Goxpyriment: A Go-Based Framework for Behavioral and Cognitive Experiments

Overview and Motivation

Goxpyriment (2604.15245) proposes a novel experimental software framework implemented in the Go programming language, tailored for behavioral and cognitive research. The framework is explicitly constructed to mitigate several limitations prevalent in Python-based experiment control tools, such as platform-specific runtime dependencies, timing uncertainties stemming from garbage collection, and asset management complexities. Central to goxpyrimentโ€™s architecture is the production of single, statically linked binaries that embed all necessary experimental assets and have zero runtime dependencies, thus streamlining both experiment deployment and reproducibility across heterogeneous laboratory environments.

Architecture and Technical Features

Goxpyriment centers its API on an Experiment object responsible for session management, safety-driven event handling (such as premature participant exits), and metadata logging. The programming model is designed to foster both clarity and flexibilityโ€”a direct inheritance from frameworks like Expyrimentโ€”while capitalizing on Go's static typing and error-checking guarantees. The Run callback structure ensures robust data preservation and hardware resource cleanup.

The framework integrates a customizable graphical participant information dialog, enhancing experiment setup efficiency and reducing the likelihood of configuration errors by allowing experimenters to specify parameters through a GUI or command-line arguments. Figure 1

Figure 1

Figure 1: Example GetParticipantInfo dialogs for Retinotopy (A) and Number-Comparison (B) paradigms, demonstrating configurable participant input GUIs to minimize setup errors and support rapid experiment launch.

A key technical achievement is goxpyrimentโ€™s explicit control over garbage collection. By leveraging Goโ€™s ability to suspend the garbage collector during timing-critical trial loops, the framework eliminates a major source of timing jitter endemic to Python and JavaScript experiment libraries. Response collection is further enhanced by the use of hardware-interrupt-level timestamps retrieved directly from SDL3โ€™s event API, yielding high-precision reaction time measurements and obviating the need for continuous polling.

For hardware synchronization, the framework employs go-sdl3 bindings, supporting VSYNC-based synchronization for visual stimuli, accurate tone generation, and serial/parallel trigger capabilities with TTL-level accuracy. Specialized streaming functions and "present stream" APIs enable precise delivery and verification of rapid, sequential stimulus presentations. The provided timing verification suite validates stimulus durations, frame-interval jitter, AV lags, and trigger reliability under real-world laboratory conditions.

Empirical Timing Characterization

The authors benchmarked goxpyrimentโ€™s temporal precision on a Raspberry Pi 4, demonstrating sub-millisecond accuracy for visual, auditory, and hardware trigger stimuli. Visual stimulus presentation showed zero skipped frames and a frame lag (~32 ms) precisely matching two monitor refresh periods at 60 Hz, while audio lags (approximately 100 ms) were consistent and compensable. The consistency of stimulus and trigger delivery, as evidenced by tight standard deviations (โ‰ค 2 ms for visual, 6 ms for audio), validates the reliability essential for empirical research.

AI-Assisted and Human-Friendly Design

Goxpyriment is explicitly designed to interface harmoniously with AI-powered coding assistants, such as Gemini and Claude. The frameworkโ€™s strong type guarantees, minimalistic and unambiguous Go syntax, and asset-embedding support mitigate common AI-driven coding errors, such as invalid API calls or file path mismatches. The manuscript illustrates how these features allow large portions of the template experiment gallery to be generated autonomously by LLMs, although human oversight remains necessary to address conceptual errors (such as mis-implemented stimuli). Figure 2

Figure 2

Figure 2: Examples of AI-generated programming outputs, including typical errors such as misrepresentation of Kanizsaโ€™s illusory rectangle and correct (rightmost) versus incorrect clock drawing responses.

Comparison with Existing Frameworks

Relative to Expyriment, PsychoPy, MATLAB/Psychtoolbox, and web-based tools (jsPsych), goxpyriment distinguishes itself through the following unique technical features:

  • Zero dependency deployment: Complete portability via single-file binaries embedding assets and resources, compared to complex package management and interpreter requirements for Python- or MATLAB-based solutions.
  • Explicit garbage collection control: Prevents timing perturbation during critical periods, dramatically improving timing fidelity compared to dynamic language environments.
  • Unified hardware abstraction: Robust SDL3-based access to visual, auditory, and hardware trigger APIs.
  • Static asset management: Through Goโ€™s //go:embed functionality, stimuli and experimental assets are compiled into the executable, eliminating run-time dependency on filesystem layouts.
  • AI coding support: The deterministic and statically typed environment yields significant advantages for projects collaborating with code-generating LLMs.

However, notable omissions in the current release include lack of support for video playback with frame-accurate timestamps, integrated eye-tracking APIs, and audio/video recording of responses. Additionally, web deployment (via WASM) is theoretically possible but not yet practical due to the immaturity of required toolchains.

Practical and Theoretical Implications

Goxpyrimentโ€™s approach has direct implications for practical experimental reproducibilityโ€”the single-binary deployment model removes many failure points related to library version drift, asset path errors, and interpreter inconsistencies. This is particularly salient for cross-lab sharing and archival experiment re-use, satisfying an increasingly urgent requirement for open, reproducible science.

From the perspective of AI-assisted scientific programming, the frameworkโ€™s minimal API surface and static guarantees provide an optimal substrate for LLM coding agents, reducing friction in automated generation and verification of experimental code. This positions goxpyriment as a reference architecture for next-generation experiment-control environments intended for hybrid human-AI programming teams.

Future development directions suggest rapid expansion into video playback, native eye-tracker and recording support, and ultimately, browser-based deployment as browser-side Go and SDL3/EMSCRIPTEN tooling matures.

Conclusion

Goxpyriment establishes a technically robust medium for behavioral and cognitive experiment programming, optimizing deployment reliability and temporal precision through the Go languageโ€™s compiled nature and explicit control over system resources. Its architecture is particularly well-adapted to both human users and AI-powered agents, and empirical timing results substantiate its applicability for high-precision experimentation. Expansion of its capabilities to video, recording, and online deployment will further consolidate its relevance as a core tool for psychological and neuroscientific research.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.