GithubHelp home page GithubHelp logo

copilot-language / copilot Goto Github PK

View Code? Open in Web Editor NEW
591.0 31.0 46.0 4.51 MB

A stream-based runtime-verification framework for generating hard real-time C code.

Home Page: http://copilot-language.github.io

Haskell 99.97% Shell 0.03%
runtime-verification rv embedded-systems c haskell stream copilot

copilot's Introduction

Copilot

Build Status Version on Hackage

Copilot is a runtime verification framework for hard real-time systems. Programs can be interpreted for testing, or translated into C99 code to be incorporated in a project or standalone application. The C99 code generated is constant in memory and time, making it suitable for systems with hard real-time requirements.

InstallationExamplesRelated projectsDocumentationContributionsAcknowledgements

Features

  • Write simple, high-level specifications using a stream-based language.

  • Produce hard real-time C99 runtime monitors that run in constant memory and time.

  • Catch errors in specifications early using expressive static type system.

  • Prove properties about specifications using theorem proving extensions.

  • Interpret specifications for testing and debugging purposes.

  • Obtain proofs of correctness of the generated code.

Table of Contents

Installation

(Back to top)

Linux installation

(Back to top)

Debian Bookworm / Ubuntu 23.04

On Debian Bookworm / Ubuntu 23.04 or newer, Copilot can be installed directly from the package repositories with:

$ sudo apt-get install libghc-copilot-dev

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Other Linux distributions

On other Linux distributions or older Debian-based distributions, to use Copilot you must install a Haskell compiler (GHC) and the package manager Cabal. We currently support all versions of GHC from 8.6.5 to modern versions (9.6 as of this writing). You can install the toolchain using ghcup or, if you are on Debian/Ubuntu, directly with apt-get:

$ sudo apt-get install ghc cabal-install

Once the compiler is installed, install Copilot from Hackage with:

cabal v2-install --lib copilot

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Mac installation

(Back to top)

To use Copilot you must have a Haskell compiler (GHC) and the package manager Cabal. We currently support all versions of GHC from 8.6.5 to modern versions (9.6 as of this writing). You can install the toolchain using ghcup, as well as with Homebrew:

$ brew install ghc cabal-install

Once the compiler is installed, install Copilot from Hackage with:

$ cabal v2-install --lib copilot

To test that Copilot is available, execute the following:

$ ghci <<< 'import Language.Copilot'

It should end with a line like the following and not print any error messages:

ghci> ghci> Leaving GHCi.

Troubleshooting

(Back to top)

Feel free to open an issue if you are unable to install Copilot following these instructions.

There is a TravisCI file at the root of the repository that may help with troubleshooting the installation. Our issues often include comments with Dockerfiles listing the steps necessary to install Copilot from scratch.

Examples

(Back to top)

Here follows a simple example of a heating system. More examples can be found in the examples directory of the main repository.

-- This example implements a simple home heating system. The system heats
-- when the temperature gets too low, and stops when it is high enough. It read
-- temperature as a byte (range -50C to 100C) and translates this to Celsius.

module Heater where

import Language.Copilot
import Copilot.Compile.C99

import Prelude hiding ((>), (<), div)

-- External temperature as a byte, ranging from -50C to 100C.
temp :: Stream Word8
temp = extern "temperature" Nothing

-- Temperature in Celsius.
--
-- We need to cast the Word8 to a Float. This is an unsafeCast, as there
-- is no direct relation between Word8 and Float.
ctemp :: Stream Float
ctemp = (unsafeCast temp) * (150.0 / 255.0) - 50.0

spec = do
  -- Triggers that fire when the ctemp is too low or too high,
  -- pass the current ctemp as an argument.
  trigger "heaton"  (ctemp < 18.0) [arg ctemp]
  trigger "heatoff" (ctemp > 21.0) [arg ctemp]

-- Compile the spec
main = reify spec >>= compile "heater"

If you save this example in a file Heater.hs and run:

$ runhaskell Heater.hs

it will produce the files heater.c, heater.h and heater_types.h, containing, respectively, the implementation of the monitors, the interface, and a declaration of any types declared in the specification (empty in this case).

If you clone the repository, the examples in the examples/ directory can be run from the root of the project. As a rule of thumb, each example is named after the filename (without extension) in lowercase letters, and directory separators replaced with a '-'. For example:

$ cabal run addmult -f examples
$ cabal run counter -f examples
$ cabal run what4-arithmetic -f examples

Related projects

(Back to top)

Disclaimer: The following projects are not part of Copilot. Their mention here does not constitute any form of endorsement.

  • Ogma is a NASA tool to facilitate the integration of safe runtime monitors into other systems, including those built using NASA's Core Flight System or the Robot Operating System (ROS 2).

  • arduino-copilot facilitates building copilot applications that run on Arduino.

  • sketch-frp-copilot extends Copilot with an FRP-like interface.

  • zephyr-copilot facilitates building copilot applications that run on boards supported by the Zephyr project.

Documentation

(Back to top)

API documentation and tutorials

(Back to top)

A tutorial on Copilot can be found here.

The API is documented throughout the different libraries and published on Hackage:

Publications

(Back to top)

The best introduction to the fundamentals of Copilot apart from the tutorial is:

Other relevant papers include:

Website

(Back to top)

For further information, including links to more documentation and the tutorial, please visit the Copilot website: https://copilot-language.github.io.

Contributions

(Back to top)

Copilot cannot accept pull requests or code contributions from developers outside the development team at this point.

If you have a question, find a bug, or would like to request a change, please file an issue adding as much information as you can to help us reproduce the error or identify the use case. Please file the issue with no labels.

Acknowledgements

(Back to top)

The Copilot team

(Back to top)

Copilot is currently maintained by:

  • Alwyn Goodloe
  • Ivan Perez

Past and current team members also include (in alphabetical order):

  • Macallan Cruff
  • Frank Dedden
  • Chris Hathhorn
  • Georges-Axel Jolayan
  • Jonathan Laurent
  • Eli Mendelson
  • Robin Morisset
  • Sebastian Niller
  • Lauren Pick
  • Lee Pike
  • Will Pogge
  • Ryan Spring
  • Laura Titolo
  • Nis Wegmann

For a complete list of contributors, including external contributors, see: https://github.com/Copilot-Language/copilot/graphs/contributors

Institutional support

(Back to top)

We are grateful for NASA Contract NNL08AD13T to Galois, Inc. and the National Institute of Aerospace, which partially supported this work.

Additionally NASA Langley contracts 80LARC17C0004 and NNL09AA00A supported further development of Copilot.

copilot's People

Contributors

a-goodloe avatar andreabedini avatar avieth avatar benjaminselfridge avatar chathhorn avatar elimendelson avatar fdedden avatar fredyr avatar hodapp87 avatar innovativeinventor avatar ivanperez-keera avatar jonathan-laurent avatar leepike avatar lmpick avatar mgc1998 avatar nathanhowell avatar ndmitchell avatar niswegmann avatar robdockins avatar ryanglscott avatar varmin123 avatar willpog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

copilot's Issues

Update examples

Update examples to match new syntax and features, remove some of them as well.

Copilot 3.0 fails to compile with GHC < 8.0

The current version of copilot fails to compile with GHC 7.*.

The issues in particular have to do with the use of underscore in type families and the syntax for language extensions. The latter is easily solvable, the former, I think not.

It might be smarter to remove these from the travis file, and add only 8.0 and 8.2 for now, unless we want to remain compatible with 7.* for some reason.

Write a developers manifest

The manifest should explain the git repo structure, and how it should be used for development and releases.

Fix printing of the interpreter

Currently, due to pretty-ncols not being updated to base >= 4.11, the interpreter is unable to show output. We should (temporarily) copy the functions in pretty-ncols to the interpreter.

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

Failure to compile with GHC >= 8.4

This library depends on pretty-ncols, which fails to compile with versions of GHC >= 8.4 (base >= 4.11) because Prelude exports (<>), which conflicts with Text.PrettyPrint.<>:

Preprocessing library pretty-ncols-0.1...
[1 of 1] Compiling Text.PrettyPrint.NCol ( Text/PrettyPrint/NCol.hs, dist/dist-sandbox-11467d12/build/Text/PrettyPrint/NCol.o )

Text/PrettyPrint/NCol.hs:27:25: error:
    Ambiguous occurrence ‘<>’
    It could refer to either ‘Prelude.<>’,
                             imported from ‘Prelude’ at Text/PrettyPrint/NCol.hs:1:8-28
                             (and originally defined in ‘GHC.Base’)
                          or ‘Text.PrettyPrint.<>’,
                             imported from ‘Text.PrettyPrint’ at Text/PrettyPrint/NCol.hs:4:1-23
                             (and originally defined in ‘Text.PrettyPrint.HughesPJ’)
   |
27 |         where buf x = x <> (hcat $ replicate q space) <> (hcat $ replicate (mx - (docLen x)) space)
   |                         ^^

Text/PrettyPrint/NCol.hs:27:55: error:
    Ambiguous occurrence ‘<>’
    It could refer to either ‘Prelude.<>’,
                             imported from ‘Prelude’ at Text/PrettyPrint/NCol.hs:1:8-28
                             (and originally defined in ‘GHC.Base’)
                          or ‘Text.PrettyPrint.<>’,
                             imported from ‘Text.PrettyPrint’ at Text/PrettyPrint/NCol.hs:4:1-23
                             (and originally defined in ‘Text.PrettyPrint.HughesPJ’)
   |
27 |         where buf x = x <> (hcat $ replicate q space) <> (hcat $ replicate (mx - (docLen x)) space)
   |                                                       ^^
cabal: Leaving directory '/tmp/cabal-tmp-19047/pretty-ncols-0.1'
Failed to install pretty-ncols-0.1
cabal: Entering directory '/tmp/cabal-tmp-19047/random-1.1'

Pretty-ncols is not on github and has not been updated in a very long time. I just sent an email to the author.

Remove tutorial.log

The file tutorial.log is a latex file uploaded by mistake. It should be removed.

Type signature for copilot-libraries/Utils/!! too strict

The type signature for the list index function !! is too strict by requiring the type variable of the list of streams and the index stream to be of the same type. This makes it impossible to index a list of Floats. See below for example and a new version with the type signature updated.
Type signature for !! now:

(!!) :: (Integral a, Typed a) => [Stream a] -> Stream a -> Stream a

Example

listF = [constF 3, constF 4]
listI = [constI32 3, constI32 (-4)]

bangbang :: (Typed a, Eq b, Num b, Typed b) => [Stream a] -> Stream b -> Stream a
bangbang ls n =
  let indices = map (constant . fromIntegral) [0 .. P.length ls - 1]
      select [] _ = last ls
      select (i:is) (x:xs) = mux (i == n) x (select is xs)
  in select indices ls

listFspec :: Spec
listFspec = do
  observer "listF" $ listF `bangbang` (constI32 0)
-- Whereas using !!
--  observer "listF!!" $ listF !! (constI32 0)
-- results in
--     Couldn't match type `Int32' with `Float'
--     Expected type: Stream Float
--       Actual type: Stream Int32
--     In the second argument of `(!!)', namely `(constI32 0)'
--     In the second argument of `($)', namely `listF !! (constI32 0)'

`Stream a` doesn't implement `(RealFrac a) => RealFrac (Stream a)`

Currently, it seems it is not possible to get either the integer (truncate) or decimal part (like modf does in C) of a Stream Double, or to truncate, say, a Stream Float into a Stream Int32 with unsafeCast.

This makes for instance difficult the implementation of combination of oscillators dealing with floating-point values, like the following (which doesn't work):

-- Program outputs analog values within the interval [0, maxAnalogOut]
maxAnalogOut = 255

type Millis = Word32

-- Milliseconds since the program has started
timeMillis :: Stream Millis
timeMillis = externFun "millis" [] (Just simu)
    where simu = [0] ++ (10 + simu)

sawtoothOsc, sinOsc :: Stream Double  -- ^ period (in milliseconds)
                   -> Stream Millis  -- ^ time since beginning
                   -> Stream Double

sawtoothOsc period millis = modf (cast millis / period)  -- decimal part

sinOsc period millis = sin $ 2*pi * cast millis / period

-- Modulate period of sawtoothOsc from output of sinOsc
intensity = maxAnalogOut * sawtoothOsc (250 * sinOsc 4000 timeMillis + 250) timeMillis

(sawtoothOsc could be expressed using only Stream Word32 but sinOsc couldn't. So we need either be able to use Doubles everywhere or to force cast a Stream Double to a Stream Word32 in order to compose the two oscillators)

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

Update README

Update readme for version 3.0 deprecating some libraries (SBV, C99, CBMC) and include the new backend (cbackend).

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

gitignore is outdated

Gitignore does not include things that new building tools use, profiling files, etc.

Failure to compile with GHC 8.6

The copilot3.0-dev branch fails to compile with GHC 8.6/base-4.12:

src/Copilot/Theorem/TransSys/Spec.hs:129:6: error:
    • Data.Map.fold is gone. Use foldr.

It compiles fine with GHC 8.4/base-4.11.

Switch arguments of `compile`

Having the prefix first and then the spec allows use to write reify spec >>= compile "prefix" in a main function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.