# The cl-forest Reference Manual

Next: , Previous: , Up: (dir)   [Contents][Index]

# The cl-forest Reference Manual

This is the cl-forest Reference Manual, generated automatically by Declt version 2.3 "Robert April" on Tue Feb 20 08:01:37 2018 GMT+0.

Next: , Previous: , Up: Top   [Contents][Index]

# CL-FOREST

Unofficial bindings to Rigetti Forest, a quantum computing service. These bindings are directly based off of the `forest` module of pyQuil.

Currently, this library is written for pedagogical example of the API, not for efficiency.

## Examples

Below are a few examples using the Rigetti Forest API.

Here we construct a Bell pair, and measure the pair. The interesting property about Bell states is that they always measure to the same value. Here we measure the Bell pair 10 times.

``````CL-FOREST> (run (quil "H 0"
"CNOT 0 1"
"MEASURE 0 [0]"
"MEASURE 1 [1]")
'(0 1)
10)

((0 0) (1 1) (1 1) (1 1) (1 1) (0 0) (0 0) (1 1) (0 0) (0 0))
``````

Next, we show that a Bell pair is exactly the state `(|00> + |11>)/sqrt(2)` by looking directly at the wavefunction.

``````CL-FOREST> (wavefunction (quil "H 0"
"CNOT 0 1"))

#(#C(0.7071067811865475d0 0.0d0) #C(0.0d0 0.0d0) #C(0.0d0 0.0d0)
#C(0.7071067811865475d0 0.0d0))
``````

We can recover the probabilities of each of these by computing the square modulus of each amplitude:

``````CL-USER> (map 'vector (lambda (a) (expt (abs a) 2)) *)

#(0.4999999999999999d0 0.0d0 0.0d0 0.4999999999999999d0)
``````

We see immediately that `|00>` and `|11>` both have a 50% chance of being observed.

## API Key

Before starting, you'll need to set your API key by setting the variable `cl-forest:*api-key*`.

``````(setf cl-forest:*api-key* "<< YOUR API KEY >>")
``````

You can check that it works by pinging the server:

``````> (cl-forest:ping)
"pong 3696180851"
``````

Once your API key is set, you can construct Quil programs (which are currently just represented as strings) conveniently using the `quil` function, and then use `run` or `wavefunction` to run that program.

Next: , Previous: , Up: Top   [Contents][Index]

## 2 Systems

The main system appears first, followed by any subsystem dependency.

Previous: , Up: Systems   [Contents][Index]

### 2.1 cl-forest

Author

Robert Smith

Apache 2.0

Description

Unofficial Common Lisp bindings to Rigetti Forest.

Dependencies
• drakma
• yason
• alexandria
• ieee-floats
Source

cl-forest.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

## 3 Files

Files are sorted by type and then listed depth-first from the systems components trees.

Previous: , Up: Files   [Contents][Index]

### 3.1 Lisp

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.1 cl-forest.asd

Location

cl-forest.asd

Systems

cl-forest (system)

Next: , Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.2 cl-forest/package.lisp

Parent

cl-forest (system)

Location

package.lisp

Packages

Previous: , Up: Lisp files   [Contents][Index]

#### 3.1.3 cl-forest/cl-forest.lisp

Dependency

package.lisp (file)

Parent

cl-forest (system)

Location

cl-forest.lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

## 4 Packages

Packages are listed by definition order.

Previous: , Up: Packages   [Contents][Index]

### 4.1 cl-forest

Package for symbols to interact with Rigetti Forest.

Source

package.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

## 5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.

Next: , Previous: , Up: Definitions   [Contents][Index]

### 5.1 Exported definitions

Next: , Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.1 Special variables

Special Variable: *api-key*
Package
Source

cl-forest.lisp (file)

Previous: , Up: Exported definitions   [Contents][Index]

#### 5.1.2 Functions

Function: ping ()

Ping the Forest server.

Package
Source

cl-forest.lisp (file)

Function: quil &rest INSTRUCTIONS

A helper function to make Quil program strings.

Package
Source

cl-forest.lisp (file)

Function: run PROGRAM ADDRESSES &optional NUM-TRIALS

Run the Quil program PROGRAM (as a string) a total number of NUM-TRIALS (default: 1) times, reading the classical bits addressed by the list of addresses ADDRESSES.

Return a list of lists of sampled bits corresponding to the requested ADDRESSES.

Package
Source

cl-forest.lisp (file)

Function: version ()

Query the version of the remote Forest software.

Package
Source

cl-forest.lisp (file)

Get the wavefunctions for the program PROGRAM. Optionally, provide a list of addresses of bits that should be returned as a second value.

Return two values:

1. The wavefunction as an array of complex numbers.

Package
Source

cl-forest.lisp (file)

Previous: , Up: Definitions   [Contents][Index]

### 5.2 Internal definitions

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.1 Constants

Constant: +octets-per-complex-double+
Package
Source

cl-forest.lisp (file)

Constant: +octets-per-double+
Package
Source

cl-forest.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.2 Special variables

Special Variable: *endpoint*
Package
Source

cl-forest.lisp (file)

Next: , Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.3 Macros

Macro: quill &rest INSTRUCTIONS

A helper function to make Quil program from LoL

Package
Source

cl-forest.lisp (file)

Previous: , Up: Internal definitions   [Contents][Index]

#### 5.2.4 Functions

Function: check-api-key ()
Package
Source

cl-forest.lisp (file)

Function: dict &rest KEY-VALS
Package
Source

cl-forest.lisp (file)

Function: post-json JSON

POST the JSON data structure (as interpreted by YASON) to Rigetti Forest.

Return two values:

1. The response payload, either as a string, an octet vector, or a stream.

2. The content length or NIL.

Package
Source

cl-forest.lisp (file)

Previous: , Up: Top   [Contents][Index]

## Appendix A Indexes

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.1 Concepts

Next: , Previous: , Up: Indexes   [Contents][Index]

### A.2 Functions

Next: , Previous: , Up: Indexes   [Contents][Index]