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.

ResourcesEstimator instance shows wrong estimates when used more than once #189

@msoeken

Description

@msoeken

Describe the bug

ResourcesEstimator does not reset internal state and a single instance cannot be used to simulate two operations.

To Reproduce

Operation.qs

namespace Namespace {
  open Microsoft.Quantum.Intrinsic;

  operation Operation1() : Unit {
    using ((a, b) = (Qubit(), Qubit())) {
      CNOT(a, b);
      CNOT(a, b);
      CNOT(a, b);
    }
  }

  operation Operation2() : Unit {
    using ((a, b) = (Qubit(), Qubit())) {
      CNOT(a, b);
      CNOT(a, b);
      CNOT(a, b);
      CNOT(a, b);
      CNOT(a, b);
    }
  }
}

Driver.cs

using System;
using Microsoft.Quantum.Simulation.Simulators;

namespace Namespace {
  public class Program {
    public static void Main(string[] args) {
      var sim = new ResourcesEstimator();

      Operation1.Run(sim).Wait();
      Console.WriteLine(sim.ToTSV());

      Operation2.Run(sim).Wait();
      Console.WriteLine(sim.ToTSV());
    }
  }
}

Expected behavior

Output should be to accumulate the estimates:

Metric          Sum            
CNOT            3
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0
Metric          Sum            
CNOT            8
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0

or to reset the estimates:

Metric          Sum            
CNOT            3
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0
Metric          Sum            
CNOT            5
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0

Actual behavior

Output currently shows the estimates for the first operation:

Metric          Sum            
CNOT            3
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0
Metric          Sum            
CNOT            3
QubitClifford   0
R               0
Measure         0
T               0
Depth           0
Width           2
BorrowedWidth   0

System information

  • Q# Version: 0.11.2004.2825
  • .NET Core Version: 3.1.201

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