qir-alliance / qat

QIR compiler tools and optimization passes for targeting QIR to different hardware backends
https://qir-alliance.github.io/qat/
MIT License
28 stars 14 forks source link

Array alias counting persisting in base profile #54

Closed peter-campora closed 2 years ago

peter-campora commented 2 years ago

I've had qat produce qir under the base profile with --disable-grouping (teleport-base.txt) and without (teleport-chain-grouping.txt) for the simple teleport chain QIR attached (teleport.txt). The main issue is that in both base profile version array alias counting operations appear in the file. The QIR in teleport.txt was produced when compiling the Q# with <PackageReference Include="Microsoft.Quantum.Type1.Core" Version="0.18.2108157818-beta" IsTargetPackage="true" /> specified in the csproj file. If there is consideration that these instructions may be allowed under the base profile, please let me know!

teleport.txt teleport-base.txt teleport-chain-grouping.txt

swernli commented 2 years ago

Good catch, @peter-campora! That definitely looks like a bug, and it appears like those might be leftover from the allocation of a qubit array in the original Q# (for leftPreshared and rightPreshared). @troelsfr would you be able to take a look? It may just be that __quantum__rt__array_update_alias_count should be added to the list of functions that get automatically and unconditionally pruned, right?

swernli commented 2 years ago

A quick look through the code shows that these instructions are already removed by another rule that handles cleaning up array access: https://github.com/qir-alliance/qat/blob/f327cdb09869cc3ae47ac23da7c1eb071e81845d/ComponentExamples/CArrayMap/main.cpp#L174-L176. Perhaps we need something similar for the qubit array handling rules?

troelsfr commented 2 years ago

@peter-campora thanks for this. I will have a look at it now and get back to you!

troelsfr commented 2 years ago

@swernli this bug seems to be a result of a rushed November. I've fixed this issue in #55 - please review when you find the time.