haquil-0.2.1.14: A Haskell implementation of the Quil instruction set for quantum computing.

Safe HaskellNone
LanguageHaskell2010

Language.Quil.Execute

Contents

Description

Executing Quil programs.

This example makes measurements on a prepared state.

>>> import Language.Quil.Execute
>>> import Language.Quil.Types

-- Run a simple program and examine the quantum and classical states..
>>> let program = [H 0, CNOT 0 1, RX (Expression . Number $ pi/4) 1]
>>> runProgramWithStdRandom 2 [BoolBit False] program
Quantum state:   0.6532814824381882|00> + -0.27059805007309845i|01> + -0.27059805007309845i|10> + 0.6532814824381882|11> @ [1,0]
Classical state: 0x0 [1]
Program counter: 3
Halted?          False

-- Add measurement to the program and re-run it.
>>> let program' = program ++ [MEASURE 0 (Just 0)]
>>> runProgramWithStdRandom 2 [BoolBit False] program'
Quantum state:   0.9238795325112867|00> + -0.3826834323650897i|10> @ [1,0]
Classical state: 0x0 [1]
Program counter: 4
Halted?          False

-- Run the program again.
>>> runProgramWithStdRandom 2 [BoolBit False] program'
Quantum state:   -0.3826834323650897i|01> + 0.9238795325112867|11> @ [1,0]
Classical state: 0x1 [1]
Program counter: 4
Halted?          False

Synopsis

Execution

runProgram Source #

Arguments

:: RandomGen g 
=> Int

The number of qubits.

-> [BitData]

The classical bits.

-> [Instruction]

The instructions.

-> Rand g Machine

Action for the resulting state of the machine.

Run a program, starting from the ground state and using the global random number generator.

runProgramWithStdGen Source #

Arguments

:: StdGen

The random number generator.

-> Int

The number of qubits.

-> [BitData]

The classical bits.

-> [Instruction]

The instructions.

-> Machine

The resulting state of the machine.

Create an action to run a program, starting from the ground state.

runProgramWithStdRandom Source #

Arguments

:: Int

The number of qubits.

-> [BitData]

The classical bits.

-> [Instruction]

The instructions.

-> IO Machine

Action for the resulting state of the machine.

Run a program, starting from the ground state and using a particular random-number generator.

executeInstructions Source #

Arguments

:: RandomGen g 
=> [Instruction]

The instructions.

-> Machine

The state of the machine.

-> Rand g Machine

Action for the resulting state of the machine.

Execute a series of instructions.

executeInstruction Source #

Arguments

:: RandomGen g 
=> Instruction

The instruction.

-> Machine

The state of the machine.

-> Rand g Machine

Action for the resulting state of the machine.

Execute an instruction.

Compilation

compileGate Source #

Arguments

:: Parameters

The formal parameters.

-> [Expression]

The expressions for the matrix elements.

-> [QBit]

Which qubits to operate on.

-> Arguments

The argument.

-> Operator

The resulting operator.

Compile a gate.

compileExpression Source #

Arguments

:: Parameters

The formal parameters.

-> Expression

The expression.

-> Arguments

The arguments.

-> Number

The result.

Compile an expression.