newsynth-0.3.0.2: Exact and approximate synthesis of quantum circuits

Safe HaskellSafe-Inferred

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.

Basic operations

tick :: StepComp ()Source

Issue a single tick.

untick :: StepComp a -> StepComp aSource

Run the step computation for one step.

forward :: Int -> StepComp a -> StepComp aSource

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

is_done :: StepComp a -> BoolSource

Check whether a step computation is completed.

get_result :: StepComp a -> Maybe aSource

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 aSource

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 -> aSource

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 aSource

Run a step computation for at most n steps.

Other operations

diverge :: StepComp aSource

Do nothing, forever.

parallel_first :: StepComp a -> StepComp a -> StepComp aSource

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.