Documentation for microsoft::quantum::RuleFactory

microsoft::quantum::RuleFactory

More...

#include <Passes/TargetQisMappingPass/Factory.hpp>

Public Types

Name
using std::shared_ptr< ReplacementRule > ReplacementRulePtr
ReplacementRule pointer type used for the construction of replacement rules.
using IAllocationManager::AllocationManagerPtr AllocationManagerPtr
Allocation manager pointer used to hold allocation managers.
using ILogger::ILoggerPtr ILoggerPtr
Interface to logger.

Public Functions

Name
RuleFactory(RuleSet & rule_set, AllocationManagerPtr qubit_alloc_manager, AllocationManagerPtr result_alloc_manager, ILoggerPtr logger)
RuleFactory()
RuleFactory(RuleFactory const & )
RuleFactory(RuleFactory && ) =default
~RuleFactory() =default
void usingConfiguration(TargetQisMappingPassConfiguration const & config)
This takes a TargetQisMappingPassConfiguration as argument and enable rules accordingly.
void removeFunctionCall(String const & name)
void useStaticQubitArrayAllocation()
void useStaticQubitAllocation()
void useStaticResultAllocation()
void resolveConstantArraySizes()
void inlineCallables()
void optimizeResultOne()
void optimizeResultZero()
Replaces branching of quantum results compared to zero.
void optimizeConstantResult()
Replaces branching of quantum constant results.
void optimizeResultComparison()
Replacing comparison between two results.
void removeGetZeroOrOne()
Removes unused quantum zeros or ones.
void disableReferenceCounting()
void disableAliasCounting()
This method disables alias counting for arrays, strings and results.
void disableStringSupport()
void disableInitializeSupport()
Removes runtime initialization instruction(s).
void disableRecordOutputSupport()
Removes output recording by removing related runtime instructions.
void setDefaultIntegerWidth(uint32_t v)
Sets the integer width used when it cannot be deducted from the context of the transformation.

Detailed Description

class microsoft::quantum::RuleFactory;

Rule factory provides a high-level methods to build a rule set that enforces certain aspects of QIR transformation.

Public Types Documentation

using ReplacementRulePtr

using microsoft::quantum::RuleFactory::ReplacementRulePtr =  std::shared_ptr<ReplacementRule>;

ReplacementRule pointer type used for the construction of replacement rules.

using AllocationManagerPtr

using microsoft::quantum::RuleFactory::AllocationManagerPtr =  IAllocationManager::AllocationManagerPtr;

Allocation manager pointer used to hold allocation managers.

using ILoggerPtr

using microsoft::quantum::RuleFactory::ILoggerPtr =  ILogger::ILoggerPtr;

Interface to logger.

Public Functions Documentation

function RuleFactory

RuleFactory(
    RuleSet & rule_set,
    AllocationManagerPtr qubit_alloc_manager,
    AllocationManagerPtr result_alloc_manager,
    ILoggerPtr logger
)

function RuleFactory

RuleFactory()

function RuleFactory

RuleFactory(
    RuleFactory const & 
)

function RuleFactory

RuleFactory(
    RuleFactory && 
) =default

function ~RuleFactory

~RuleFactory() =default

function usingConfiguration

void usingConfiguration(
    TargetQisMappingPassConfiguration const & config
)

This takes a TargetQisMappingPassConfiguration as argument and enable rules accordingly.

function removeFunctionCall

void removeFunctionCall(
    String const & name
)

Removes all calls to functions with a specified name. This function matches on name alone and ignores function arguments.

function useStaticQubitArrayAllocation

void useStaticQubitArrayAllocation()

Static qubit array allocation identifies allocations, array access and releases. Each of these are replaced with static values. Patterns recognized include

%array = call %Array* @__quantum__rt__qubit_allocate_array(i64 10)

which is replaced by a constant pointer

%array = inttoptr i64 0 to %Array*

The array allocation is managed through the qubit allocation manager. Access to qubit arrays

%0 = call i8* @__quantum__rt__array_get_element_ptr_1d(%Array* %array, i64 7)
%1 = bitcast i8* %0 to %Qubit**
%qubit = load %Qubit*, %Qubit** %1, align 8

is replaced by off-setting the array value by 7 to get

%qubit = inttoptr i64 7 to %Qubit*

Finally, release is recognized and the allocation manager is invoked accordingly.

Allocation

This rule is replacing the allocate qubit array instruction

leftPreshared = call Array* @__quantum__rt__qubit_allocate_array(i64 2)

by changing it to a constant pointer

leftPreshared = inttoptr i64 0 to Array*

In this way, we use the

Release replacement

function useStaticQubitAllocation

void useStaticQubitAllocation()

Static qubit allocation identifies allocation and release of single qubits. It uses the qubit allocation manager to track allocation and releases of qubits. It translates

%qubit1 = call %Qubit* @__quantum__rt__qubit_allocate()
%qubit2 = call %Qubit* @__quantum__rt__qubit_allocate()
%qubit3 = call %Qubit* @__quantum__rt__qubit_allocate()
%qubit4 = call %Qubit* @__quantum__rt__qubit_allocate()
%qubit5 = call %Qubit* @__quantum__rt__qubit_allocate()

to

%qubit1 = inttoptr i64 0 to %Qubit*
%qubit2 = inttoptr i64 1 to %Qubit*
%qubit3 = inttoptr i64 2 to %Qubit*
%qubit4 = inttoptr i64 3 to %Qubit*
%qubit5 = inttoptr i64 4 to %Qubit*

if the BasicAllocationManager is used.

Release replacement

function useStaticResultAllocation

void useStaticResultAllocation()

Static allocation of results. This feature is similar to useStaticQubitAllocation but uses the result allocation manager.

function resolveConstantArraySizes

void resolveConstantArraySizes()

function inlineCallables

void inlineCallables()

function optimizeResultOne

void optimizeResultOne()

Replaces branching of quantum results compared to one. This is a relatively advanced pattern, intended for base adaptor-like constructs where

%1 = tail call %Result* @__quantum__rt__result_get_one()
%2 = tail call i1 @__quantum__rt__result_equal(%Result* %0, %Result* %1)
br i1 %2, label %then0__1, label %continue__1

is mapped into

%1 = call i1 @__quantum__qis__read_result__body(%Result* %0)
br i1 %1, label %then0__1, label %continue__1

which removes the need for constant one.

function optimizeResultZero

void optimizeResultZero()

Replaces branching of quantum results compared to zero.

function optimizeConstantResult

void optimizeConstantResult()

Replaces branching of quantum constant results.

function optimizeResultComparison

void optimizeResultComparison()

Replacing comparison between two results.

function removeGetZeroOrOne

void removeGetZeroOrOne()

Removes unused quantum zeros or ones.

function disableReferenceCounting

void disableReferenceCounting()

This method disables reference counting for arrays, strings and results. It does so by simply removing the instructions and the resulting code is expected to be executed either on a stack VM or with shared pointer logic.

function disableAliasCounting

void disableAliasCounting()

This method disables alias counting for arrays, strings and results.

function disableStringSupport

void disableStringSupport()

Removes string support by removing string related instructions. At the moment these include __quantum__rt__string_create, __quantum__rt__string_update_reference_count, __quantum__rt__string_update_alias_count and __quantum__rt__message.

function disableInitializeSupport

void disableInitializeSupport()

Removes runtime initialization instruction(s).

function disableRecordOutputSupport

void disableRecordOutputSupport()

Removes output recording by removing related runtime instructions.

function setDefaultIntegerWidth

void setDefaultIntegerWidth(
    uint32_t v
)

Sets the integer width used when it cannot be deducted from the context of the transformation.


Updated on 1 August 2023 at 16:25:10 UTC