Class Visitor¶
Defined in File Blackbird.h
Inheritance Relationships¶
Base Type¶
public blackbirdBaseVisitor
Class Documentation¶
-
class blackbird::Visitor : public blackbirdBaseVisitor¶
The main Blackbird visitor. This visitor is invoked implicitly via the
parse
function to parse the Blackbird script.The methods defined in this class describe how to traverse the abstract syntax tree describing the blackbird program, how to extract and evaluate arrays, variables, expressions, and quantum programs.
Public Functions
-
template<class O>
O *_create_operation(blackbirdParser::ArgumentsContext *ctx, intvec modes)¶ Factory function to create Blackbird operations corresponding to those provided in the Blackbird script.
- Parameters
ctx –
ArgumentsContext
modes –
std::vector<int>
containing the modes the operation is applied to
- Returns
the operation
-
antlrcpp::Any visitNumber(blackbirdParser::NumberContext *ctx)¶
Defines what the visitor does when a
NumberContext
is visited.Here, it gets the string representing the number, and calls various helper functions to convert Blackbird complex, float, and int to the C++ equivalent.
- Parameters
ctx –
NumberContext
- Returns
returns the number literal
-
antlrcpp::Any visitExpressionvar(blackbirdParser::ExpressionvarContext *ctx)¶
Defines what the visitor does when an
ExpressionvarContext
is visited.Here, it gets the variable name and the variable type, and starts the process of extracting the variable based on the declared type.
- Parameters
ctx –
ExpressionvarContext
- Returns
returns 0 to indicate successful visitation
-
antlrcpp::Any visitArrayvar(blackbirdParser::ArrayvarContext *ctx)¶
Defines what the visitor does when a
ArrayvarContext
is visited.Here, it gets the name and type of the array variable, initializes a vector corresponding to the declared type, and stores it either in the
complexmat_vars
,floatmat_vars
, orintmat_vars
dictionary.- Parameters
ctx –
NumberContext
-
antlrcpp::Any visitArrayrow(blackbirdParser::ArrayrowContext*)¶
Defines what the visitor does when a
ArrayrowContext
is visited.Here, it extracts the column element values, and populates the row by manually visiting each child element.
- Parameters
ctx –
ArrayrowContext
- Returns
the array row vector
-
antlrcpp::Any visitStatement(blackbirdParser::StatementContext *ctx)¶
Defines what to do as each quantum operation in the device context is visited.
In general, this includes:
Getting the number of modes the operation is applied to using
split_string_to_ints
If the statement is an operation:
Get the number of arguments/types of the arguments
Evaluate the arguments
Use
_create_operation
template to create the new operation object, actingon the specified number of modes, with the specified arguments
Add this operation to the
program->operations
vector.
Repeat the previous steps for any measurements.
- Parameters
ctx –
StatementContext
- Returns
0 to specify correct visitation.
-
antlrcpp::Any visitProgram(blackbirdParser::ProgramContext *ctx)¶
Defines what to do as each quantum operation in the device context is visited.
In general, this includes:
Getting the number of modes the operation is applied to using
split_string_to_ints
If the statement is an operation:
Get the number of arguments/types of the arguments
Evaluate the arguments
Use
_create_operation
template to create the new operation object, actingon the specified number of modes, with the specified arguments
Add this operation to the
program->operations
vector.
Repeat the previous steps for any measurements.
- Parameters
ctx –
StatementContext
- Returns
0 to specify correct visitation.
-
antlrcpp::Any visitStart(blackbirdParser::StartContext *ctx)¶
Starts the visitation process of parsing the Blackbird code.
- Parameters
ctx –
StartContext
- Returns
returns the blackbird program, containing device information, metadata, and the quantum program to run
Public Members
-
std::unordered_map<std::string, std::complex<double>> complex_vars¶
Unordered map mapping from blackbird complex variable names to
std::complex<double>
values.
-
std::unordered_map<std::string, double> float_vars¶
Unordered map mapping from blackbird float variable names to
double
values
-
std::unordered_map<std::string, int> int_vars¶
Unordered map mapping from blackbird int variable names to
int
values
-
std::unordered_map<std::string, std::string> str_vars¶
Unordered map mapping from blackbird string variable names to
std::string
values
-
std::unordered_map<std::string, bool> bool_vars¶
Unordered map mapping from blackbird bool variable names to
bool
values
-
std::unordered_map<std::string, complexmat> complexmat_vars¶
Unordered map mapping from blackbird complex array variable names to
complexmat
values.
-
std::unordered_map<std::string, floatmat> floatmat_vars¶
Unordered map mapping from blackbird float array variable names to
floatmat
values.
-
template<class O>