Skip to content

SwiftProjectOrganization/SwiftStanApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftStanApp

Purpose

A macOS app that exposes cmdstan methods from MacOS or iOS clients. It also supports an experimental port of the ulam() R method in Statistical Rethinking and it's supporting R package rethinking.

It will also declare a subset of the methods as App Intents, making them available from Shortcuts, Siri, and Spotlight.

SwiftStan related repositories (the 'SwiftStan suite')

The SwiftStanApp is a thin HTTP client of SwiftStanServer. The SwiftStanServer contains the SwiftStanLibrary, which provides access to make and cmdstan to compile and execute Stan Language Programs. As stated above, SwiftStanApp is a MacOS or IOS app. The SwiftStanServer + SwiftStanLibrary + cmdstan run on a single (MacOS) system.

The SwiftStanLibrary is based on the SwiftStan CLI and provides the cmdstan and direct ulam capabilities. The CLI also includes a second ulam pipeline using an intermediate DSL that requires swiftc. As swiftc is not available on iOS platforms that functionality was dropped from the SwiftStanLibrary SPM package.

Ultimately my personal dream setup will have a Mac Mini M6 running the SwiftStanServer and use tools, for example as suggested here (YMMV!), to run Stan models when on the road.

Requirements

  • macOS 27.0 + Xcode 27.0
  • SwiftStanServer
  • cmdstan

The workflow envisioned in the SwiftStan suite depends on the availability of a shared (e.g. iCloud based) ~/Documents directory where models, data and results are stored. In my setup I will pick up the result files (e.g. ~/Documents/<Stan_Cases>//Results/.stansummary.csv) with R, Julia, Swift or Python.

Building

Clone SwiftStanApp from https://github.com/SwiftProjectOrganization/SwiftStanApp. It will open in Xcode. Build it.

Configuration

Launch the SwiftStanApp app and enter the server URL in the text field (leave blank for the default http://127.0.0.1:8080 if the SwiftStanApp and SwiftStanServer reside on the same MacOS system). SwiftStanServer must be running before invoking any command, intent or model selection.

Available Commands

Command Shortcut phrase Description
Compile "Compile a Stan model" Compile a Stan model in ~/Documents/<StanCases>
Sample "Sample with cmdstan" Run HMC/NUTS sampling
Optimize "Optimize a Stan model" Run cmdstan optimize
Oathfinder "Run Pathfinder" Run cmdstan pathfinder
Laplace "Run Laplace" Run cmdstan laplace
Generated Q\uantities "Generate quantities" Run cmdstan generate_quantities
Stansummary "Summarize Stan samples" Run stansummary on output CSV files
Ulam "Run ulam" Run the full Ulam → Stan → sample pipeline
Stancode "Generate Stan code with SwiftStan" Translate .alist.r to .stan source
Csv to Json "Convert .csv to .json" Convert .csv + .stan to a .data.json file
Stan to Alist ".stan -> .alist.r" Convert .stan to .alist.r format
Alist to DSL ".alist.r -> DSL" Convert Alist to DSL format
Runinfo "Read .config.json" Extract metadata from a cmdstan run
Stancases "Show <Stan_Cases>" Use swiftstan stancases SR2Cases to set <Stan_Cases>

All commands operate on a model parameter (default: bernoulli) matching a subdirectory under ~/Documents/<StanCases>. The parameter <StanCases> is set in the main UI window of SwiftStanApp.

Architecture

Shortcuts / Siri / Spotlight
         │  AppIntent.perform()
         ▼
  SwiftStanApp          ← this repo
   (OpenAPI client)
         │  HTTP POST /v1/<op>
         ▼
   (Hummingbird)
  SwiftStanServer 
         │
         ▼
  SwiftStanLibrary
   (library → cmdstan)

The app has no compile-time dependency on SwiftStanLibrary or SwiftStanServer. The shared contract is openapi.yaml (kept byte-identical to the server's canonical copy).

Related Projects

About

Initial attempt at AppIntent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages