newsynth-0.4.0.0: Exact and approximate synthesis of quantum circuits

Quantum.Synthesis.StepComp

Description

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

Synopsis

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

 Source # Methods(>>=) :: StepComp a -> (a -> StepComp b) -> StepComp b #(>>) :: StepComp a -> StepComp b -> StepComp b #return :: a -> StepComp a #fail :: String -> StepComp a # Source # Methodsfmap :: (a -> b) -> StepComp a -> StepComp b #(<\$) :: a -> StepComp b -> StepComp a # Source # Methodspure :: 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 # MethodsshowsPrec :: Int -> StepComp a -> ShowS #show :: StepComp a -> String #showList :: [StepComp a] -> ShowS #

Basic operations

Issue a single tick.

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.

Check whether a step computation is completed.

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

Do nothing, forever.

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.