newsynth-0.3.0.5: Exact and approximate synthesis of quantum circuits

Safe HaskellSafe
LanguageHaskell98

Quantum.Synthesis.StepComp

Contents

Description

This module provides step computations. These are computations that can be run, stopped, resumed, parallelized, and/or bounded in runtime.

Synopsis

A monad for step computations

data StepComp a Source #

A step computation can be run for a specified number of steps, stopped, continued, and interleaved. Such a computation produces "ticks" at user-defined intervals, which must be consumed by the environment for the computation to continue.

Constructors

Done a

Terminate with a result.

Tick (StepComp a)

Produce a "tick", then resume the computation.

Instances

Monad StepComp Source # 

Methods

(>>=) :: StepComp a -> (a -> StepComp b) -> StepComp b #

(>>) :: StepComp a -> StepComp b -> StepComp b #

return :: a -> StepComp a #

fail :: String -> StepComp a #

Functor StepComp Source # 

Methods

fmap :: (a -> b) -> StepComp a -> StepComp b #

(<$) :: a -> StepComp b -> StepComp a #

Applicative StepComp Source # 

Methods

pure :: a -> StepComp a #

(<*>) :: StepComp (a -> b) -> StepComp a -> StepComp b #

liftA2 :: (a -> b -> c) -> StepComp a -> StepComp b -> StepComp c #

(*>) :: StepComp a -> StepComp b -> StepComp b #

(<*) :: StepComp a -> StepComp b -> StepComp a #

Show a => Show (StepComp a) Source # 

Methods

showsPrec :: Int -> StepComp a -> ShowS #

show :: StepComp a -> String #

showList :: [StepComp a] -> ShowS #

Basic operations

tick :: StepComp () Source #

Issue a single tick.

untick :: StepComp a -> StepComp a Source #

Run the step computation for one step.

forward :: Int -> StepComp a -> StepComp a Source #

Fast-forward a computation by n steps. This is essentially equivalent to doing n untick operations.

is_done :: StepComp a -> Bool Source #

Check whether a step computation is completed.

get_result :: StepComp a -> Maybe a Source #

Retrieve the result of a completed step computation (or Nothing if it is incomplete).

subtask :: Int -> StepComp a -> StepComp (StepComp a) Source #

Run a subsidiary computation for up to n steps, translated into an equal number of steps of the parent computation.

speedup :: Int -> StepComp a -> StepComp a Source #

Run a subtask, speeding it up by a factor of n ≥ 1. Every 1 tick of the calling task corresponds to up to n ticks of the subtask.

parallel :: StepComp a -> StepComp b -> StepComp (Either (a, StepComp b) (StepComp a, b)) Source #

Run two step computations in parallel, until one branch terminates. Tick allocation is associative: each tick of the parent function translates into one tick for each subcomputation. Therefore, when running, e.g., three subcomputations in parallel, they will each receive an approximately equal number of ticks.

with_counter :: StepComp a -> StepComp (a, Int) Source #

Wrap a step computation to return the number of steps, in addition to the result.

Run functions

run :: StepComp a -> a Source #

Run a step computation until it finishes.

run_with_steps :: StepComp a -> (a, Int) Source #

Run a step computation until it finishes, and also return the number of steps it took.

run_bounded :: Int -> StepComp a -> Maybe a Source #

Run a step computation for at most n steps.

Other operations

diverge :: StepComp a Source #

Do nothing, forever.

parallel_first :: StepComp a -> StepComp a -> StepComp a Source #

Run two step computations in parallel. The first one to complete becomes the result of the computation.

parallel_maybe :: StepComp (Maybe a) -> StepComp (Maybe b) -> StepComp (Maybe (a, b)) Source #

Run two step computations in parallel. If either computation returns Nothing, return Nothing. Otherwise, return the pair of results.

parallel_list_maybe :: [StepComp (Maybe a)] -> StepComp (Maybe [a]) Source #

Run a list of step computations in parallel. If any computation returns Nothing, return Nothing. Otherwise, return the list of results.