libqasm
library for handling cQASM files
Public Member Functions | Public Attributes | List of all members
cqasm::v1::instruction::Instruction Class Reference

Representation of an available instruction (also known as gate) in the instruction set, without parameters bound to it (note that libqasm cannot match instructions based on which qubits are used; you'll need to do that on your own). More...

Public Member Functions

 Instruction (const std::string &name, const std::string &param_types="", bool allow_conditional=true, bool allow_parallel=true, bool allow_reused_qubits=false, bool allow_different_index_sizes=false)
 Creates a new instruction. More...
 
bool operator== (const Instruction &rhs) const
 Equality operator. More...
 
bool operator!= (const Instruction &rhs) const
 Inequality operator. More...
 

Public Attributes

std::string name
 The name of the instruction. More...
 
types::Types param_types
 The vector of parameter types that this instruction expects. More...
 
bool allow_conditional
 Whether this instruction supports conditional execution by means of the c- notation. More...
 
bool allow_parallel
 Whether this instruction can be used in a bundle. More...
 
bool allow_reused_qubits
 Whether to allow usage of the same qubit in different arguments. More...
 
bool allow_different_index_sizes
 Whether different index sizes are allowed. More...
 

Detailed Description

Representation of an available instruction (also known as gate) in the instruction set, without parameters bound to it (note that libqasm cannot match instructions based on which qubits are used; you'll need to do that on your own).

A number of these can be registered into libqasm by the program or library using it through register_instruction(), to inform libqasm of the supported instruction set. For each instruction, libqasm needs to know its name, which parameters it expects, and a few extra flags in order to be able to resolve the instruction and check for errors in the cQASM file. The resolved instruction type is part of the cqasm::semantic::Instruction node present in the semantic tree returned through the parse result structure.

Note that it is legal to have multiple instructions with the same name, as long as they can be distinguished through their parameter types (i.e. instructions can be overloaded).

You can add any data you like to these through the Annotatable interface for your own bookkeeping, so you don't have to maintain an additional map from this error model structure to your own internal structure if you're okay with using this one.

Definition at line 46 of file cqasm-v1-instruction.hpp.

#include <cqasm-v1-instruction.hpp>

Inheritance diagram for cqasm::v1::instruction::Instruction:
Inheritance graph
[legend]
Collaboration diagram for cqasm::v1::instruction::Instruction:
Collaboration graph
[legend]

Constructor & Destructor Documentation

◆ Instruction()

cqasm::v1::instruction::Instruction::Instruction ( const std::string &  name,
const std::string &  param_types = "",
bool  allow_conditional = true,
bool  allow_parallel = true,
bool  allow_reused_qubits = false,
bool  allow_different_index_sizes = false 
)
explicit

Creates a new instruction.

param_types is a shorthand type specification string as parsed by cqasm::types::from_spec(). If you need more control, you can also manipulate param_types directly.

allow_conditional specifies whether the instruction can be made conditional with c- notation. allow_parallel specifies whether it may appear bundled with other instructions. allow_reused_qubits specifies whether it is legal for the instruction to use a qubit more than once in its parameter list. allow_different_index_sizes specifies whether it's legal to have different "index sizes" for different parameters, for instance q[1,2] in one parameter and q[1,2,3,4,5] in another.

Definition at line 26 of file cqasm-v1-instruction.cpp.

Member Function Documentation

◆ operator==()

bool cqasm::v1::instruction::Instruction::operator== ( const Instruction rhs) const

Equality operator.

Definition at line 45 of file cqasm-v1-instruction.cpp.

◆ operator!=()

bool cqasm::v1::instruction::Instruction::operator!= ( const Instruction rhs) const
inline

Inequality operator.

Definition at line 115 of file cqasm-v1-instruction.hpp.

Member Data Documentation

◆ name

std::string cqasm::v1::instruction::Instruction::name

The name of the instruction.

Names are matched case insensitively.

Definition at line 52 of file cqasm-v1-instruction.hpp.

◆ param_types

types::Types cqasm::v1::instruction::Instruction::param_types

The vector of parameter types that this instruction expects.

Definition at line 57 of file cqasm-v1-instruction.hpp.

◆ allow_conditional

bool cqasm::v1::instruction::Instruction::allow_conditional

Whether this instruction supports conditional execution by means of the c- notation.

This is normally true.

Definition at line 63 of file cqasm-v1-instruction.hpp.

◆ allow_parallel

bool cqasm::v1::instruction::Instruction::allow_parallel

Whether this instruction can be used in a bundle.

This is normally true.

Definition at line 68 of file cqasm-v1-instruction.hpp.

◆ allow_reused_qubits

bool cqasm::v1::instruction::Instruction::allow_reused_qubits

Whether to allow usage of the same qubit in different arguments.

This is normally false, as this makes no sense in QM, in which case libqasm will report an error to the user if a qubit is reused. Setting this to true just disables that check.

Definition at line 76 of file cqasm-v1-instruction.hpp.

◆ allow_different_index_sizes

bool cqasm::v1::instruction::Instruction::allow_different_index_sizes

Whether different index sizes are allowed.

This is normally false, as index lists are normally used to designate parallel instructions, and it makes no sense for the lists to mismatch in that case.

Definition at line 83 of file cqasm-v1-instruction.hpp.


The documentation for this class was generated from the following files: