GateFunction

class GateFunction : public xacc::Function, public std::enable_shared_from_this<GateFunction>

The GateFunction is a realization of Function for gate-model quantum computing. It is composed of GateInstructions that are themselves derivations of the Instruction class.

Subclassed by xacc::quantum::ConditionalFunction

Public Functions

GateFunction(const std::string &name)

The constructor, takes the function unique id and its name.

Parameters
  • id:

  • name:

void mapBits(std::vector<int> bitMap)

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

Parameters
  • bitMap: The bits to map to

const int nInstructions()

Return the number of Instructions that this Function contains.

Return

nInst The number of instructions

InstPtr getInstruction(const int idx)

Return the Instruction at the given index.

Return

inst The instruction at the given index.

Parameters

std::list<InstPtr> getInstructions()

Return all Instructions in this Function

Return

insts The list of this Function’s Instructions

std::shared_ptr<Function> enabledView()

Return a view of this Function that only contains enabled instructions.

Return

enabledFunction The Function of all enabled instructions.

void enable()

Enable this Instruction.

void removeInstruction(const int idx)

Remove an instruction from this quantum intermediate representation

Parameters
  • instructionID:

void addInstruction(InstPtr instruction)

Add an instruction to this quantum intermediate representation.

Parameters
  • instruction:

void replaceInstruction(const int idx, InstPtr replacingInst)

Replace the given current quantum instruction with the new replacingInst quantum Instruction.

Parameters
  • currentInst:

  • replacingInst:

void insertInstruction(const int idx, InstPtr newInst)

Insert a new Instruction at the given index. All previous instructions are pushed back, ie their new indices are currentIndex + 1.

Parameters
  • idx: The index where the new instruction should be inserted

  • newInst: The new Instruction to insert.

const std::string name() const

Return the name of this function

Return

const std::string description() const

Return the description of this instance

Return

description The description of this object.

const std::vector<int> bits()

Return the qubits this function acts on.

Return

const int depth()

Return the depth of this Function, applicable for Functions that represent quantum circuits.

Return

depth The depth of the list of instructions.

const std::string persistGraph()

Persist this Function to a graph representation.

Return

graph The graph represented as a string, like a DOT file

const std::string toString(const std::string &bufferVarName)

Return an assembly-like string representation for this function .

Return

Parameters
  • bufferVarName:

const std::string toString()

Return this instruction’s assembly-like string representation.

Return

qasm The instruction as qasm

InstructionParameter getParameter(const int idx) const

Return this Instruction’s parameter at the given index.

Return

param The InstructionParameter at the given index.

Parameters
  • idx: The index of the parameter.

void setParameter(const int idx, InstructionParameter &inst)

Set this Instruction’s parameter at the given index.

Parameters
  • idx: The index of the parameter

  • inst: The instruction.

void addParameter(InstructionParameter instParam)

Add a parameter to this Function.

@ param The parameter to add to this Function.

std::vector<InstructionParameter> getParameters()

Return all of this Instruction’s parameters.

Return

params This instructions parameters.

bool isParameterized()

Return true if this Instruction is parameterized.

Return

parameterized True if this Instruction has parameters.

const int nParameters()

Return the number of InstructionParameters this Instruction contains.

Return

nInsts The number of instructions.

std::shared_ptr<Function> operator()(const std::vector<double> &params)

Evaluate this parameterized function at the given concrete parameters.

Parameters
  • params: A vector of parameters

const int nLogicalBits()

Return the number of logical qubits.

Return

nLogical The number of logical qubits.

const int nPhysicalBits()

Return the number of physical qubits.

Return

nPhysical The number of physical qubits.

bool hasOptions()

Return true if this Instruction has customizable options.

Return

hasOptions

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

Set the value of an option with the given name.

Parameters
  • optName: The name of the option.

  • option: The value of the option

InstructionParameter getOption(const std::string optName)

Get the value of an option with the given name.

Return

option The value of the option.

Parameters
  • optName: Then name of the option.

std::map<std::string, InstructionParameter> getOptions()

Return all the Instructions options as a map.

Return

optMap The options map.