This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 923
/
Copy pathQuantumVizEstimator.cs
59 lines (49 loc) · 2.29 KB
/
QuantumVizEstimator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#nullable enable
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime;
using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;
namespace Microsoft.Quantum.Simulation.Simulators
{
public class QuantumVizEstimator : QCTraceSimulator
{
private QuantumVizCounter? operationsCounter;
public static QCTraceSimulatorConfiguration RecommendedConfig() =>
new QCTraceSimulatorConfiguration
{
CallStackDepthLimit = 4,
ThrowOnUnconstrainedMeasurement = false,
UseDistinctInputsChecker = false,
UseInvalidatedQubitsUseChecker = false,
UsePrimitiveOperationsCounter = false,
UseDepthCounter = true,
UseWidthCounter = true
};
public QuantumVizEstimator() : this(RecommendedConfig()) {}
public QuantumVizEstimator(QCTraceSimulatorConfiguration config) : base(WithoutPrimitiveOperationsCounter(config))
{
}
private static QCTraceSimulatorConfiguration WithoutPrimitiveOperationsCounter(QCTraceSimulatorConfiguration config)
{
config.UsePrimitiveOperationsCounter = false;
return config;
}
protected override void InitializeQCTracerCoreListeners(IList<IQCTraceSimulatorListener> listeners)
{
base.InitializeQCTracerCoreListeners(listeners);
var primitiveOperationsIdToNames = new Dictionary<int, string>();
Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.Utils.FillDictionaryForEnumNames<PrimitiveOperationsGroups, int>(primitiveOperationsIdToNames);
var cfg = new PrimitiveOperationsCounterConfiguration {
primitiveOperationsNames = primitiveOperationsIdToNames.Values.ToArray()
};
operationsCounter = new QuantumVizCounter(cfg);
this.tCoreConfig.Listeners.Add(operationsCounter);
}
// We can guarantee that <c>operationsCounter</c> is not null, because
// <c>InitializeQCTracerCoreListeners</c> is called by the constructor.
public Circuit Circuit => operationsCounter!.Circuit;
}
}