Blackbird Program class¶
Module name: blackbird.program
This module contains a Python class representing a Blackbird program using standard Python data types.
The functions load()
, and loads()
will read Blackbird scripts
and return an instance of the BlackbirdProgram
class.
Summary¶
|
Converts a numpy array to a Blackbird script array type. |
|
Python representation of a Blackbird program. |
Code details¶
- numpy_to_blackbird(A, var_name)[source]¶
Converts a numpy array to a Blackbird script array type.
- Parameters
A (array) – 2-dimensional NumPy array
var_name (str) – the array variable name
- Returns
- list containing each line representing the
Blackbird array variable declaration
- Return type
list[str]
- class BlackbirdProgram(name='blackbird_program', version='1.0')[source]¶
Python representation of a Blackbird program.
- property name¶
Name of the Blackbird program
- Returns
name
- Return type
str
- property version¶
Version of the Blackbird parser the program targets
- Returns
version number
- Return type
str
- property modes¶
A set of non-negative integers specifying the mode numbers the program manipulates.
- Returns
mode numbers
- Return type
set[int]
- property target¶
Contains information regarding the target device of the quantum program (i.e., the target device the Blackbird script is compiled for).
Important keys include:
'name'
(Union[str, None]): the name of the device the Blackbird script requests to berun on. If no target is requested, the returned value will be
None
.
'options'
(dict): a dictionary of keyword arguments for the target device
- Returns
target information
- Return type
dict[str->[str, dict]]
- property programtype¶
Information regarding the type of program that is to be run on the device.
Important keys include:
'name'
(Union[str, None]): the name of the type of program that is to be run on thedevice (e.g. ‘TDM’). If no type is requested, the returned value will be
None
.
'options'
(dict): a dictionary of keyword arguments for the type (e.g. ‘copies’)
- Returns
type information
- Return type
dict[str->[str, dict]]
- property operations¶
List of operations to apply to the device, in temporal order.
Each operation is contained as a dictionary, with the following keys:
'op'
(str): the name of the operation'args'
(list): a list of positional arguments for the operation'kwargs'
(dict): a dictionary of keyword arguments for the operation'modes'
(list[int]): modes the operation applies to
Note that, depending on the operation, both
'args'
and'kwargs'
might be empty.- Returns
operation information
- Return type
list[dict]
- property parameters¶
List of free parameters the Blackbird script depends on.
- Returns
list of free parameter names
- Return type
List[str]
- property variables¶
List of variables in the Blackbird program.
- Returns
dictionary of variables
- Return type
dict[str, float]
- is_template()[source]¶
Returns
True
if there is at least one free parameter.- Returns
True if a template
- Return type
bool
- __call__(**kwargs)[source]¶
Create a new Blackbird program, with all free parameters initialized to their passed values.
- Return type
Program
- __len__()[source]¶
The length of the quantum program (i.e., the number of operations applied).
- Returns
program length
- Return type
int
- serialize()[source]¶
Serializes the blackbird program, returning a valid Blackbird script as a string.
- Returns
the blackbird script representing the BlackbirdProgram object
- Return type
str
- __weakref__¶
list of weak references to the object (if defined)