Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Building Scientific Experiments Using F# Functional Programming
1. Building scientific
experiments with F#
A. Tcholakov, B. L. Green, A. C. Frangeskou, C. J. Stephen, P. Diggle,
J. Lishman, T. Wheeler, M. E. Newton, and G. W. Morley
2. A. Tcholakov, B. L. Green, A. C. Frangeskou, C. J. Stephen, P. Diggle,
J. Lishman, T. Wheeler, M. E. Newton, and G. W. Morley
Building scientific
experiments with F#
3. A. Tcholakov, B. L. Green, A. C. Frangeskou, C. J. Stephen, P. Diggle,
J. Lishman, T. Wheeler, M. E. Newton, and G. W. Morley
Building scientific
experiments with F#
4. A. Tcholakov, B. L. Green, A. C. Frangeskou, C. J. Stephen, P. Diggle,
J. Lishman, T. Wheeler, M. E. Newton, and G. W. Morley
Building scientific
experiments with F#
5. A. Tcholakov, B. L. Green, A. C. Frangeskou, C. J. Stephen, P. Diggle,
J. Lishman, T. Wheeler, M. E. Newton, and G. W. Morley
Building scientific
experiments with F#
6. Anatomy of an experiment
PC
Output
device
Input
device
Science!
@ant_pt
7. • Concurrent control of multiple devices
• Cancellation
• Reporting of partial progress
• Signal processing
• Robust error handling
• Good performance
Requirements
@ant_pt
8. • Concurrent control of multiple devices
• Cancellation
• Reporting of partial progress
• Signal processing
• Robust error handling
• Good performance
Requirements… and solutions
Async<'T>
IObservable<'T>
Choice<'T1,'T2> or exn?
}
}
@ant_pt
9. • Software isn’t actually the key output
• Experiments start as prototypes
• Need path to fully-fledged application
Requirements (process)
@ant_pt
10. • National Instruments VISA
• C API + DLL import
• Typically very imperative and stateful
• Inherently Async, MailboxProcessor-like
Instrument I/O
@ant_pt
11. Command-request agent
• Module for creating MailboxProcessor agents
which process Command or Request messages
• Instrument APIs often have large surface area
• Propagates errors to caller without stopping the
agent
@ant_pt
13. Oscilloscope
• Essential tool in a
physics lab
• Records voltages
against time
• Has settings for
triggering, input
range, offset, etc.
Source: “Oscilloscope.” Wikipedia: The Free Encyclopaedia.
Wikimedia Foundation, Inc. 20 Mar 2016. Web. 13 Apr 2016.
@ant_pt
15. PicoScope agent: review
• Async but still imperative
• Device is typically used in one of several modes:
streaming, block acquisition, etc.
• Functional approach:
- model acquisition configuration
- define workflow to run a general acquisition
- push sample blocks via IObservable<'T>
@ant_pt
26. N-V-
spectrometer: review
• Declarative streaming API makes code
straightforward to read, write, and modify
• IObservable<'T> + FSharp.Control.Reactive
offer a powerful way to implement DSP
• FSharp.Charting is great for prototyping
• Async provides robust cancellation support
• MailboxProcessor ensures sequential I/O
@ant_pt
28. 397 GHz spectrometer
• Irradiate sample with
397 GHz mm-waves
• Sweep field on
superconducting
magnet system
• Measure what comes
back and stream
data with PicoScope
@ant_pt
32. Confocal microscope
Pulse length
(1ns resolution)
Integrated
photon counts
Acquisition
parameters
System development time: ~9 months
Oscillations represent
manipulation of a qubit!
@ant_pt
33. Performance
• Hasn’t really been a problem
• PicoScope streaming acquisition copes with 32ns
sample interval (fastest available) in .fsx
• Time tagging acquisition copes with several
million photon counts per second
@ant_pt
34. Towards open source…
• Aim to publish the code under Apache 2.0
• Wrappers for several common lab instruments
• First need to:
- migrate to Paket, FAKE
- make namespaces consistent
- consolidate git branches
- write some unit tests (?)
@ant_pt
35. Conclusions
• F# is a great fit for instrument control thanks to
powerful Async, Reactive programming features
• Functional paradigm + .fsx aids prototyping
• Units of measure are the cherry on top
• Working towards open source instrument
libraries
@ant_pt