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

Add more metrics to resource estimator #801

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adithyabsk
Copy link

Draft pull request adding additional metrics to resource estimator.

@ghost
Copy link

ghost commented Aug 19, 2021

CLA assistant check
All CLA requirements met.

@guenp guenp changed the title Add new files Add more metrics to resource estimator Sep 7, 2021
Copy link
Member

@msoeken msoeken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @adithyabsk. I left some comments.


namespace Simulator
{
public class ResourcesEstimatorWithAdditionalPrimitiveOperations : ResourcesEstimator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this class should be merged directly with the code in the ResourcesEstimator class.

return config;
}

protected virtual IDictionary<string, IEnumerable<Type>>? AdditionalOperations { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally made a property to be generic for arbitrary additional operations. I think it's okay to hard code the additional operators and not providing this property when merging it with the ResourcesEstimator class.

using Microsoft.Quantum.Simulation.Core;
using Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime;

namespace Simulator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace should be Microsoft.Quantum.Simulation.Simulators

Comment on lines +16 to +22
// public override Task<O> Run<T, I, O>(I args)
// {
// var result = base.Run<T, I, O>(args).Result;
// var name = typeof(T).Name;
// File.WriteAllText($"{name}.txt", ToTSV());
// return Task.Run(() => result);
// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// public override Task<O> Run<T, I, O>(I args)
// {
// var result = base.Run<T, I, O>(args).Result;
// var name = typeof(T).Name;
// File.WriteAllText($"{name}.txt", ToTSV());
// return Task.Run(() => result);
// }

Comment on lines +37 to +42
// CCNOT(a, b, c);
// T(a);
// T(b);

// Original QDK ResEst. -> 9 Ts
// New QDK ResEst. -> 1 CCZ, 2 Ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should contain some context of what it is trying to express. Also referring to Original and New estimator may be misleading.

trow["Sum"] = (double)trow["Sum"] - 4 * (double)androw["Sum"] - 7 * (double)cczrow["Sum"];
trow["Max"] = (double)trow["Max"] - 4 * (double)androw["Max"] - 7 * (double)cczrow["Max"];

// TODO: update CNOT, QubitClifford, and Measure as well
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One should measure the cost of the other metrics in ApplyAnd, CCZ and Adjoint ApplyAnd to correctly adjust the cost metrics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best approach is to run a simple Q# project, e.g.,

namespace ResEst {
  operation Count() : Unit {
    use (a, b, c) = (Qubit(), Qubit(), Qubit());
    Microsoft.Quantum.Canon.ApplyAnd(a, b, c);
  }
}

and run this against the current resources estimator to retrieve the numbers to subtract from the other metrics.

Comment on lines +65 to +75
#region Direct access to counts
public long CNOT => (long)(double)Data!.Rows!.Find("CNOT")![1];
public long QubitClifford => (long)(double)Data!.Rows!.Find("QubitClifford")![1];
public long T => (long)(double)Data!.Rows!.Find("T")![1];
public long Measure => (long)(double)Data!.Rows!.Find("Measure")![1];
public long QubitCount => (long)(double)Data!.Rows!.Find("QubitCount")![1];
public long Depth => (long)(double)Data!.Rows!.Find("Depth")![1];
public long CCZ => (long)(double)Data!.Rows!.Find("CCZ")![1];
public long And => (long)(double)Data!.Rows!.Find("And")![1];
public long AdjointAnd => (long)(double)Data!.Rows!.Find("AdjointAnd")![1];
#endregion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to remove this part and possibly add it as another pull request that targets on making such properties available.

Comment on lines +77 to +85
public override O Execute<T, I, O>(I args)
{
var result = base.Execute<T, I, O>(args);
Console.WriteLine("");
Console.WriteLine("---BEGIN TABLE---");
Console.WriteLine(ToTSV());
Console.WriteLine("---END TABLE---");
return result;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public override O Execute<T, I, O>(I args)
{
var result = base.Execute<T, I, O>(args);
Console.WriteLine("");
Console.WriteLine("---BEGIN TABLE---");
Console.WriteLine(ToTSV());
Console.WriteLine("---END TABLE---");
return result;
}

@adithyabsk adithyabsk force-pushed the t-abalaji/update-resource-estimator branch from 5c38f9c to 4f3147b Compare December 16, 2021 05:09
@adithyabsk
Copy link
Author

So some quick updates from my end, there were some issues getting a unit test set up that used used the ApplyAnd gate. I assume this was because it is a newer gate and the current project targets version 0.18.2109163417-beta of the Microsoft.Quantum.Sdk. I looked through the release notes but was not able to pinpoint the exact version this gate was introduced, without having to dig through the commit history.

Regardless, trying to bump the version the runtime builds ended up with its own set of issues since it seems that the AutoSubstitution project requires that specific version of the sdk. Even discounting that, there were a set of other issues that cropped up on upgrade.

I've set up a [simple toy branch](https://github.com/adithyabsk/qsharp-runtime/tree/unitTestRepro that demonstrates this.

@kuzminrobin
Copy link
Contributor

Doesn't it make sense to move forward with this PR or close it?
The PR has been pending for more than a year.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants