Program#

class Program(instructions: list | None = None)#

The class representing the quantum program.

A Program object can be used with the with statement. In this context all the instructions could be specified.

Example usage:

import numpy as np
import piquasso as pq

with pq.Program() as program:
    pq.Q() | pq.Vacuum()

    pq.Q(0) | pq.Squeezing(r=0.5)

    pq.Q(0, 1) | pq.Beamsplitter(theta=np.pi / 4)

simulator = pq.GaussianSimulator(d=5)
result = simulator.execute(program)

One may also create a Piquasso program by directly providing the set of instructions as constructor argument:

program = pq.Program(
    instructions=[
        pq.Vacuum(),
        pq.Squeezing(r=0.5).on_modes(0),
        pq.Beamsplitter(theta=np.pi / 4).on_modes(0, 1),
    ]
)
simulator = pq.GaussianSimulator(d=5)
result = simulator.execute(program)
Variables:

instructions – The instructions in the program.

Parameters:

instructions (list[Instruction], optional) – The set of instructions, e.g. quantum gates and measurements.

classmethod from_dict(dict_: dict) Program#

Creates a Program instance from a dict.

The currently supported format is:

{
    "instructions": [
        {
            "type": <INSTRUCTION_CLASS_NAME>,
            "attributes": {
                "constructor_kwargs": <CONSTRUCTOR_KWARGS_IN_DICT_FORMAT>,
                "modes": <LIST_OF_MODES>
            }
        }
    ]
}
Parameters:

dict (dict) – The Program in a key-value pair format.

Returns:

A Program initialized using the specified dict.

Return type:

Program

load_blackbird(filename: str) None#

Loads the gates to be applied into instructions from a BlackBird file (.xbb).

Parameters:

filename (str) – Location of a Blackbird program (.xbb).

loads_blackbird(string: str) None#

Loads the gates to apply into instructions from a string representing a BlackbirdProgram.

Parameters:

string (str) – String containing a valid Blackbird program.