# sf.program¶

Warning

Unless you are a Strawberry Fields developer, you likely do not need to use these classes directly.

See the Program class for details on Strawberry Fields programs.

This module implements the Program class which acts as a representation for quantum circuits.

## Quantum circuit representation¶

The Command instances in the circuit form a strict partially ordered set in the sense that the order in which the operations have to be executed is usually not completely fixed. For example, operations acting on different subsystems always commute with each other. We denote $$a < b$$ if $$a$$ has to be executed before $$b$$. Each strict partial order corresponds to a directed acyclic graph (DAG), and the transitive closure of any DAG is a strict partial order. Three different (but equivalent) representations of the circuit are used.

• Initially, the circuit is represented as a Command queue (list), listing the Commands in the temporal order they are applied.

• The second representation, grid, essentially mimics a quantum circuit diagram. It is a mapping from subsystem indices to lists of Commands touching that subsystem, where each list is temporally ordered.

• Finally, the quantum circuit can be represented using a DAG by making each Command a node, and drawing an edge from each Command to all its immediate followers along each wire it touches. It can be converted back into a command queue by popping a maximal element until the graph is empty, that is, consuming it in a topological order. Note that a topological order is not always unique, there may be several equivalent topological orders.

The three representations can be converted to each other using the functions list_to_grid(), grid_to_DAG() and DAG_to_list().