Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Depth and Width are inconsistent #1037

@sam-jaques

Description

@sam-jaques

Describe the bug

When qubits are allocated and released during a function call in a loop, the reported depth corresponds to a circuit where all function calls occur in parallel, but the reported width does not account for all qubits that must be simultaneously allocated.

To Reproduce

The following code creates the issue when run with the QTraceSimulator with OptimizeDepth=true in it's configuration.

operation Test(): Unit {
        let blockNum = 4;
        let blockSize = 4;
        use inputs = Qubit[blockSize*blockNum]{
            for i in 0..blockNum - 1 {
                use anc = Qubit[blockSize]{
                    for k in 1..4
                    {
                        for j in 0..blockSize-1 
                        {
                            T(inputs[i*blockSize+j]);
                            T(anc[j]);
                        }

                    }
                }
            }
        }

Expected behavior

The function Test should have T-depth 4 but width of 4*(4+4) = 48. At the very least, the number of T-gates should be at most the product of T-depth and the total width.

Actual behavior

When run on Test, the trace simulator outputs:

  • initial width = 0
  • extra width = 20
  • T-depth = 4
  • T-count = 128
    Notice that the t-depth times the total width (which should be an upper bound on the T-count) is 80, but it claims a T-count of 128

System information

  • Q# version 0.24.210930

  • OS: Ubuntu 20.04

  • .NET Core Version: 6.0.300

Additional context

This is roughly the same bug that was supposed to be fixed here: #404.

Setting OptimizeDepth=false gives the expected behaviour: extra width is 36, but the T-depth is 16.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions