From 268f66dd51636bbc776eb15cf1afccb00a729f46 Mon Sep 17 00:00:00 2001 From: Irina Yatsenko Date: Thu, 18 Jun 2020 13:34:27 -0700 Subject: [PATCH 1/4] Clarify the meaning of depth/width metrics in ResourceEstimator --- .../Circuits/ResourcesEstimator.qs | 12 +++++++++++ .../ResourcesEstimatorTests.cs | 21 ++++++++++++++++++- .../ResourcesEstimator/ResourcesEstimator.cs | 8 +++++-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs index 8d34b42448c..0fc38043e4b 100644 --- a/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs +++ b/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs @@ -16,4 +16,16 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests ResetAll([q[1], q[0]]); } } + + // This operation has to choose between optimizing depth + // or width of the cirquit. + operation DepthVersusWidth () : Unit + { + using(q = Qubit()) { + T(q); + } + using(q = Qubit()) { + T(q); + } + } } diff --git a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs index 5fa9728a0d0..6454767ca96 100644 --- a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs +++ b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs @@ -74,7 +74,7 @@ public void VerifyDataTest() Assert.Equal(1.0, data.Rows.Find("CNOT")["Sum"]); Assert.Equal(0.0, data.Rows.Find("R")["Sum"]); Assert.Equal(2.0, data.Rows.Find("QubitClifford")["Sum"]); - Assert.Equal(3.0, data.Rows.Find("Width")["Sum"]); + Assert.Equal(3.0, data.Rows.Find("WidthLowerBound")["Sum"]); } /// @@ -101,5 +101,24 @@ public void ToTSVTest() Assert.Equal(2, cliffords.Length); Assert.Equal("2", cliffords[1]); } + + /// + /// Documents that the width and depth statistics reflect independent lower + /// bounds for each. + /// + [Fact] + public void VerifyDepthAndWidthTest() + { + var sim = new ResourcesEstimator(); + + DepthVersusWidth.Run(sim).Wait(); + var data = sim.Data; + + // It's impossible to distribute two T operators over circuit of depth one + // and width one. The results reflect _independent_ lower bounds for each metric. + Assert.Equal(2.0, data.Rows.Find("T")["Sum"]); + Assert.Equal(1.0, data.Rows.Find("WidthLowerBound")["Sum"]); + Assert.Equal(1.0, data.Rows.Find("DepthLowerBound")["Sum"]); + } } } diff --git a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs index ec0e80ddef1..01e0ac524af 100644 --- a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs +++ b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs @@ -78,7 +78,11 @@ public ResourcesEstimator(QCTraceSimulatorConfiguration config) : base(config) } else if (name == MetricsNames.WidthCounter.ExtraWidth) { - return "Width"; + return "WidthLowerBound"; + } + else if (name == MetricsNames.DepthCounter.Depth) + { + return "DepthLowerBound"; } else { @@ -156,7 +160,7 @@ public virtual DataTable Data /// /// Returns in TSV format where the key is the Metric name, - /// and the value is the statistics in tab-seperated format. + /// and the value is the statistics in tab-separated format. /// public virtual string ToTSV() { From c0eacd85dc4c4328144cffa10265f9bb0e42fa2e Mon Sep 17 00:00:00 2001 From: Irina Yatsenko Date: Thu, 18 Jun 2020 14:28:34 -0700 Subject: [PATCH 2/4] Added one more test to document depth metric --- .../Circuits/ResourcesEstimator.qs | 12 ++++++++++-- .../ResourcesEstimatorTests.cs | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs b/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs index 0fc38043e4b..b209762cc09 100644 --- a/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs +++ b/src/Simulation/Simulators.Tests/Circuits/ResourcesEstimator.qs @@ -17,8 +17,16 @@ namespace Microsoft.Quantum.Simulation.Simulators.Tests } } - // This operation has to choose between optimizing depth - // or width of the cirquit. + // Tests for Depth and Width lower bounds + operation DepthDifferentQubits () : Unit + { + using(q = Qubit[3]) { + T(q[0]); + T(q[1]); + T(q[2]); + T(q[0]); + } + } operation DepthVersusWidth () : Unit { using(q = Qubit()) { diff --git a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs index 6454767ca96..8070d3a0bb1 100644 --- a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs +++ b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs @@ -107,15 +107,27 @@ public void ToTSVTest() /// bounds for each. /// [Fact] - public void VerifyDepthAndWidthTest() + public void DepthDifferentQubitsTest() { var sim = new ResourcesEstimator(); + // using(q = Qubit[3]) { T(q[0]); T(q[1]); T(q[3]); T(q[0]); } + DepthDifferentQubits.Run(sim).Wait(); + var data = sim.Data; + + Assert.Equal(4.0, data.Rows.Find("T")["Sum"]); + Assert.Equal(3.0, data.Rows.Find("WidthLowerBound")["Sum"]); + Assert.Equal(2.0, data.Rows.Find("DepthLowerBound")["Sum"]); + } + [Fact] + public void DepthVersusWidthTest() + { + var sim = new ResourcesEstimator(); + + // using(q = Qubit()) { T(q); } using(q = Qubit()) { T(q); } (yes, twice) DepthVersusWidth.Run(sim).Wait(); var data = sim.Data; - // It's impossible to distribute two T operators over circuit of depth one - // and width one. The results reflect _independent_ lower bounds for each metric. Assert.Equal(2.0, data.Rows.Find("T")["Sum"]); Assert.Equal(1.0, data.Rows.Find("WidthLowerBound")["Sum"]); Assert.Equal(1.0, data.Rows.Find("DepthLowerBound")["Sum"]); From 9068a3a19741994755f181a64b8b3c8a67efd2e3 Mon Sep 17 00:00:00 2001 From: Irina Yatsenko Date: Thu, 18 Jun 2020 15:33:02 -0700 Subject: [PATCH 3/4] Normalize line endings to Unix --- .../Simulators/ResourcesEstimator/ResourcesEstimator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs index 01e0ac524af..f59fa61f635 100644 --- a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs +++ b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs @@ -81,8 +81,8 @@ public ResourcesEstimator(QCTraceSimulatorConfiguration config) : base(config) return "WidthLowerBound"; } else if (name == MetricsNames.DepthCounter.Depth) - { - return "DepthLowerBound"; + { + return "DepthLowerBound"; } else { From d36c926df496065c09e1cd2d629c1dbbdeab472a Mon Sep 17 00:00:00 2001 From: Irina Yatsenko Date: Wed, 24 Jun 2020 13:40:09 -0700 Subject: [PATCH 4/4] Keep the old Depth/Width names for the tracer statistics --- .../ResourcesEstimatorTests.cs | 26 ++++++++++++------- .../ResourcesEstimator/ResourcesEstimator.cs | 8 ++---- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs index 8070d3a0bb1..2128f458764 100644 --- a/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs +++ b/src/Simulation/Simulators.Tests/ResourcesEstimatorTests.cs @@ -74,7 +74,7 @@ public void VerifyDataTest() Assert.Equal(1.0, data.Rows.Find("CNOT")["Sum"]); Assert.Equal(0.0, data.Rows.Find("R")["Sum"]); Assert.Equal(2.0, data.Rows.Find("QubitClifford")["Sum"]); - Assert.Equal(3.0, data.Rows.Find("WidthLowerBound")["Sum"]); + Assert.Equal(3.0, data.Rows.Find("Width")["Sum"]); } /// @@ -100,11 +100,11 @@ public void ToTSVTest() var cliffords = rows.First(r => r.StartsWith("QubitClifford")).Split('\t'); Assert.Equal(2, cliffords.Length); Assert.Equal("2", cliffords[1]); - } - + } + /// - /// Documents that the width and depth statistics reflect independent lower - /// bounds for each. + /// Shows that T gates on different qubits are counted for depth purposes as + /// executing in parallel. /// [Fact] public void DepthDifferentQubitsTest() @@ -116,9 +116,15 @@ public void DepthDifferentQubitsTest() var data = sim.Data; Assert.Equal(4.0, data.Rows.Find("T")["Sum"]); - Assert.Equal(3.0, data.Rows.Find("WidthLowerBound")["Sum"]); - Assert.Equal(2.0, data.Rows.Find("DepthLowerBound")["Sum"]); - } + Assert.Equal(3.0, data.Rows.Find("Width")["Sum"]); + Assert.Equal(2.0, data.Rows.Find("Depth")["Sum"]); + } + + /// + /// Documents that the width and depth statistics reflect independent lower + /// bounds for each (two T gates cannot be combined into a circuit of depth + /// one and width one). + /// [Fact] public void DepthVersusWidthTest() { @@ -129,8 +135,8 @@ public void DepthVersusWidthTest() var data = sim.Data; Assert.Equal(2.0, data.Rows.Find("T")["Sum"]); - Assert.Equal(1.0, data.Rows.Find("WidthLowerBound")["Sum"]); - Assert.Equal(1.0, data.Rows.Find("DepthLowerBound")["Sum"]); + Assert.Equal(1.0, data.Rows.Find("Width")["Sum"]); + Assert.Equal(1.0, data.Rows.Find("Depth")["Sum"]); } } } diff --git a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs index f59fa61f635..ec0e80ddef1 100644 --- a/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs +++ b/src/Simulation/Simulators/ResourcesEstimator/ResourcesEstimator.cs @@ -78,11 +78,7 @@ public ResourcesEstimator(QCTraceSimulatorConfiguration config) : base(config) } else if (name == MetricsNames.WidthCounter.ExtraWidth) { - return "WidthLowerBound"; - } - else if (name == MetricsNames.DepthCounter.Depth) - { - return "DepthLowerBound"; + return "Width"; } else { @@ -160,7 +156,7 @@ public virtual DataTable Data /// /// Returns in TSV format where the key is the Metric name, - /// and the value is the statistics in tab-separated format. + /// and the value is the statistics in tab-seperated format. /// public virtual string ToTSV() {