Instruction

class Instruction : public xacc::BaseInstructionVisitable, public xacc::Identifiable

The Instruction interface is the base of all XACC Intermediate Representation Instructions for post-Moore’s law accelerated computing. The Instruction, at its core, provides an Instruction name and a set of next-gen bits that the Instruction operates on. Instructions can also be enabled or disabled. Instructions implement BaseInstructionVisitable to enable visitor pattern functionality across all Instruction subclasses.

Instruction can also expose 0 to N InstructionParameters. InstructionParameters can be an int, double, float, or string.

Subclassed by xacc::Function, xacc::IRGenerator, xacc::quantum::Anneal, xacc::quantum::DWQMI, xacc::quantum::GateInstruction

Public Functions

virtual const std::string toString(const std::string &bufferVarName) = 0

Persist this Instruction to an assembly-like string with a given bit buffer variable name.

Return

str The assembly-like string.

Parameters

virtual const std::string toString() = 0

Persist this Instruction to an assembly-like string.

Return

str The assembly-like string.

virtual const std::vector<int> bits() = 0

Return the indices of the bits that this Instruction operates on.

Return

bits The bits this Instruction operates on.

virtual InstructionParameter getParameter(const int idx) const = 0

Return this Instruction’s parameter at the given index.

Return

param The InstructionParameter at the given index.

Parameters
  • idx: The index of the parameter.

virtual std::vector<InstructionParameter> getParameters() = 0

Return all of this Instruction’s parameters.

Return

params This instructions parameters.

virtual void setParameter(const int idx, InstructionParameter &inst) = 0

Set this Instruction’s parameter at the given index.

Parameters
  • idx: The index of the parameter

  • inst: The instruction.

virtual const int nParameters() = 0

Return the number of InstructionParameters this Instruction contains.

Return

nInsts The number of instructions.

virtual bool isParameterized()

Return true if this Instruction is parameterized.

Return

parameterized True if this Instruction has parameters.

virtual void mapBits(std::vector<int> bitMap) = 0

Map bits [0,1,2,…] to [bitMap[0],bitMap[1],…]

Parameters
  • bitMap: The bits to map to

virtual bool isComposite()

Returns true if this Instruction is composite, ie, contains other Instructions.

Return

isComposite True if this is a composite Instruction

virtual bool isEnabled()

Returns true if this Instruction is enabled

Return

enabled True if this Instruction is enabled.

virtual void disable()

Disable this Instruction

virtual void enable()

Enable this Instruction.

virtual bool hasOptions()

Return true if this Instruction has customizable options.

Return

hasOptions

virtual void setOption(const std::string optName, InstructionParameter option) = 0

Set the value of an option with the given name.

Parameters
  • optName: The name of the option.

  • option: The value of the option

virtual InstructionParameter getOption(const std::string optName) = 0

Get the value of an option with the given name.

Return

option The value of the option.

Parameters
  • optName: Then name of the option.

virtual std::map<std::string, InstructionParameter> getOptions() = 0

Return all the Instructions options as a map.

Return

optMap The options map.

virtual void customVisitAction(BaseInstructionVisitor &visitor)

Provide a mechanism for contributing custom visit actions. This can be used to dynamically add new visit() methods to existing InstructionVisitor classes.

Parameters
  • visitor: The visitor visiting this instruction.

virtual ~Instruction()

The destructor