Merge pull request #2 from sam-jaques/sjaques-version-update
Version update and resource estimation fixes
This commit is contained in:
Коммит
fe65e0b29f
|
@ -7,7 +7,7 @@ namespace BoyarPeralta11
|
|||
open Microsoft.Quantum.Intrinsic;
|
||||
open QUtilities;
|
||||
|
||||
operation ForwardSBox(u: Qubit[], s: Qubit[], t: Qubit[], m: Qubit[], l: Qubit[], costing: Bool) : Unit
|
||||
operation ForwardSBox(u: Qubit[], s: Qubit[], t: Qubit[], m: Qubit[], l: Qubit[], anc: Qubit[], costing: Bool) : Unit
|
||||
{
|
||||
body (...)
|
||||
{
|
||||
|
@ -39,69 +39,75 @@ namespace BoyarPeralta11
|
|||
LPXOR(t[3-1], t[16-1], t[26-1]);
|
||||
LPXOR(t[1-1], t[12-1], t[27-1]);
|
||||
|
||||
LPAND(t[13-1], t[6-1], m[1-1], costing);
|
||||
LPAND(t[23-1], t[8-1], m[2-1], costing);
|
||||
LPXOR(t[14-1], m[1-1], m[3-1]);
|
||||
LPAND(t[19-1], u[7], m[4-1], costing);
|
||||
LPXOR(m[4-1], m[1-1], m[5-1]);
|
||||
LPAND(t[3-1], t[16-1], m[6-1], costing);
|
||||
LPAND(t[22-1], t[9-1], m[7-1], costing);
|
||||
LPXOR(t[26-1], m[6-1], m[8-1]);
|
||||
LPAND(t[20-1], t[17-1], m[9-1], costing);
|
||||
LPXOR(m[9-1], m[6-1], m[10-1]);
|
||||
LPAND(t[1-1], t[15-1], m[11-1], costing);
|
||||
LPAND(t[4-1], t[27-1], m[12-1], costing);
|
||||
LPXOR(m[12-1], m[11-1], m[13-1]);
|
||||
LPAND(t[2-1], t[10-1], m[14-1], costing);
|
||||
LPXOR(m[14-1], m[11-1], m[15-1]);
|
||||
LPXOR(m[3-1], m[2-1], m[16-1]);
|
||||
LPXOR(m[5-1], t[24-1], m[17-1]);
|
||||
LPXOR(m[8-1], m[7-1], m[18-1]);
|
||||
LPXOR(m[10-1], m[15-1], m[19-1]);
|
||||
LPXOR(m[16-1], m[13-1], m[20-1]);
|
||||
LPXOR(m[17-1], m[15-1], m[21-1]);
|
||||
LPXOR(m[18-1], m[13-1], m[22-1]);
|
||||
LPXOR(m[19-1], t[25-1], m[23-1]);
|
||||
LPXOR(m[22-1], m[23-1], m[24-1]);
|
||||
LPAND(m[22-1], m[20-1], m[25-1], costing);
|
||||
LPXOR(m[21-1], m[25-1], m[26-1]);
|
||||
LPXOR(m[20-1], m[21-1], m[27-1]);
|
||||
LPXOR(m[23-1], m[25-1], m[28-1]);
|
||||
LPAND(m[28-1], m[27-1], m[29-1], costing);
|
||||
LPAND(m[26-1], m[24-1], m[30-1], costing);
|
||||
LPAND(m[20-1], m[23-1], m[31-1], costing);
|
||||
LPAND(m[27-1], m[31-1], m[32-1], costing);
|
||||
LPXOR(m[27-1], m[25-1], m[33-1]);
|
||||
LPAND(m[21-1], m[22-1], m[34-1], costing);
|
||||
LPAND(m[24-1], m[34-1], m[35-1], costing);
|
||||
LPXOR(m[24-1], m[25-1], m[36-1]);
|
||||
LPXOR(m[21-1], m[29-1], m[37-1]);
|
||||
LPXOR(m[32-1], m[33-1], m[38-1]);
|
||||
LPXOR(m[23-1], m[30-1], m[39-1]);
|
||||
LPXOR(m[35-1], m[36-1], m[40-1]);
|
||||
LPXOR(m[38-1], m[40-1], m[41-1]);
|
||||
LPXOR(m[37-1], m[39-1], m[42-1]);
|
||||
LPXOR(m[37-1], m[38-1], m[43-1]);
|
||||
LPXOR(m[39-1], m[40-1], m[44-1]);
|
||||
LPXOR(m[42-1], m[41-1], m[45-1]);
|
||||
LPAND(m[44-1], t[6-1], m[46-1], costing);
|
||||
LPAND(m[40-1], t[8-1], m[47-1], costing);
|
||||
LPAND(m[39-1], u[7], m[48-1], costing);
|
||||
LPAND(m[43-1], t[16-1], m[49-1], costing);
|
||||
LPAND(m[38-1], t[9-1], m[50-1], costing);
|
||||
LPAND(m[37-1], t[17-1], m[51-1], costing);
|
||||
LPAND(m[42-1], t[15-1], m[52-1], costing);
|
||||
LPAND(m[45-1], t[27-1], m[53-1], costing);
|
||||
LPAND(m[41-1], t[10-1], m[54-1], costing);
|
||||
LPAND(m[44-1], t[13-1], m[55-1], costing);
|
||||
LPAND(m[40-1], t[23-1], m[56-1], costing);
|
||||
LPAND(m[39-1], t[19-1], m[57-1], costing);
|
||||
LPAND(m[43-1], t[3-1], m[58-1], costing);
|
||||
LPAND(m[38-1], t[22-1], m[59-1], costing);
|
||||
LPAND(m[37-1], t[20-1], m[60-1], costing);
|
||||
LPAND(m[42-1], t[1-1], m[61-1], costing);
|
||||
LPAND(m[45-1], t[4-1], m[62-1], costing);
|
||||
LPAND(m[41-1], t[2-1], m[63-1], costing);
|
||||
|
||||
LPANDWithAux(t[13-1], t[6-1], m[1-1], anc[0], costing); // depth 0->1
|
||||
LPANDWithAux(t[23-1], t[8-1], m[2-1], anc[1], costing); // depth 0->1
|
||||
LPANDWithAux(t[19-1], u[7], m[4-1], anc[2], costing); // depth 0->1
|
||||
LPANDWithAux(t[3-1], t[16-1], m[6-1], anc[3], costing); // depth 0->1
|
||||
LPANDWithAux(t[22-1], t[9-1], m[7-1], anc[4], costing); // depth 0->1
|
||||
LPANDWithAux(t[20-1], t[17-1], m[9-1], anc[5], costing); // depth 0->1
|
||||
LPANDWithAux(t[1-1], t[15-1], m[11-1], anc[6], costing); // depth 0->1
|
||||
LPANDWithAux(t[4-1], t[27-1], m[12-1], anc[7], costing); // depth 0->1
|
||||
LPANDWithAux(t[2-1], t[10-1], m[14-1], anc[8], costing); // depth 0->1
|
||||
|
||||
LPXOR(t[14-1], m[1-1], m[3-1]); // depth 1->1
|
||||
LPXOR(m[4-1], m[1-1], m[5-1]); // depth 1->1
|
||||
LPXOR(t[26-1], m[6-1], m[8-1]); // depth 1->1
|
||||
LPXOR(m[9-1], m[6-1], m[10-1]); // depth 1->1
|
||||
LPXOR(m[12-1], m[11-1], m[13-1]); // depth 1->1
|
||||
LPXOR(m[14-1], m[11-1], m[15-1]); // depth 1->1
|
||||
LPXOR(m[3-1], m[2-1], m[16-1]); // depth 1->1
|
||||
LPXOR(m[5-1], t[24-1], m[17-1]); // depth 1->1
|
||||
LPXOR(m[8-1], m[7-1], m[18-1]); // depth 1->1
|
||||
LPXOR(m[10-1], m[15-1], m[19-1]); // depth 1->1
|
||||
LPXOR(m[16-1], m[13-1], m[20-1]); // depth 1->1
|
||||
LPXOR(m[17-1], m[15-1], m[21-1]); // depth 1->1
|
||||
LPXOR(m[18-1], m[13-1], m[22-1]); // depth 1->1
|
||||
LPXOR(m[19-1], t[25-1], m[23-1]); // depth 1->1
|
||||
LPXOR(m[22-1], m[23-1], m[24-1]); // depth 1->1
|
||||
LPANDWithAux(m[22-1], m[20-1], m[25-1], anc[0], costing); // depth 1->2
|
||||
|
||||
LPXOR(m[21-1], m[25-1], m[26-1]); // depth 2->2
|
||||
LPXOR(m[20-1], m[21-1], m[27-1]); // depth 2->2
|
||||
LPXOR(m[23-1], m[25-1], m[28-1]); // depth 2->2
|
||||
LPANDWithAux(m[28-1], m[27-1], m[29-1], anc[0], costing); // depth 2->3
|
||||
LPANDWithAux(m[26-1], m[24-1], m[30-1], anc[1], costing); // depth 2->3
|
||||
LPANDWithAux(m[20-1], m[23-1], m[31-1], anc[2], costing); // depth 2->3
|
||||
LPANDWithAux(m[21-1], m[22-1], m[34-1], anc[3], costing); // depth 2->3
|
||||
|
||||
LPANDWithAux(m[27-1], m[31-1], m[32-1], anc[0], costing); // depth 3->4
|
||||
LPANDWithAux(m[24-1], m[34-1], m[35-1], anc[1], costing); // depth 3->4
|
||||
LPXOR(m[21-1], m[29-1], m[37-1]); // depth 3->3
|
||||
LPXOR(m[23-1], m[30-1], m[39-1]); // depth 3->3
|
||||
LPXOR(m[37-1], m[39-1], m[42-1]); // depth 3->3
|
||||
|
||||
LPXOR(m[27-1], m[25-1], m[33-1]); // depth 4->4
|
||||
LPXOR(m[24-1], m[25-1], m[36-1]); // depth 4->4
|
||||
LPXOR(m[32-1], m[33-1], m[38-1]); // depth 4->4
|
||||
LPXOR(m[35-1], m[36-1], m[40-1]); // depth 4->4
|
||||
LPXOR(m[38-1], m[40-1], m[41-1]); // depth 4->4
|
||||
LPXOR(m[37-1], m[38-1], m[43-1]); // depth 4->4
|
||||
LPXOR(m[39-1], m[40-1], m[44-1]); // depth 4->4
|
||||
LPXOR(m[42-1], m[41-1], m[45-1]); // depth 4->4
|
||||
LPANDWithAux(m[44-1], t[6-1], m[46-1], anc[0], costing); // depth 4->5
|
||||
LPANDWithAux(m[40-1], t[8-1], m[47-1], anc[1], costing); // depth 4->5
|
||||
LPANDWithAux(m[39-1], u[7], m[48-1], anc[2], costing); // depth 4->5
|
||||
LPANDWithAux(m[43-1], t[16-1], m[49-1], anc[3], costing); // depth 4->5
|
||||
LPANDWithAux(m[38-1], t[9-1], m[50-1], anc[4], costing); // depth 4->5
|
||||
LPANDWithAux(m[37-1], t[17-1], m[51-1], anc[5], costing); // depth 4->5
|
||||
LPANDWithAux(m[42-1], t[15-1], m[52-1], anc[6], costing); // depth 4->5
|
||||
LPANDWithAux(m[45-1], t[27-1], m[53-1], anc[7], costing); // depth 4->5
|
||||
LPANDWithAux(m[41-1], t[10-1], m[54-1], anc[8], costing); // depth 4->5
|
||||
|
||||
LPANDWithAux(m[44-1], t[13-1], m[55-1], anc[0], costing); // depth 5->6
|
||||
LPANDWithAux(m[40-1], t[23-1], m[56-1], anc[1], costing); // depth 5->6
|
||||
LPANDWithAux(m[39-1], t[19-1], m[57-1], anc[2], costing); // depth 5->6
|
||||
LPANDWithAux(m[43-1], t[3-1], m[58-1], anc[3], costing); // depth 5->6
|
||||
LPANDWithAux(m[38-1], t[22-1], m[59-1], anc[4], costing); // depth 5->6
|
||||
LPANDWithAux(m[37-1], t[20-1], m[60-1], anc[5], costing); // depth 5->6
|
||||
LPANDWithAux(m[42-1], t[1-1], m[61-1], anc[6], costing); // depth 5->6
|
||||
LPANDWithAux(m[45-1], t[4-1], m[62-1], anc[7], costing); // depth 5->6
|
||||
LPANDWithAux(m[41-1], t[2-1], m[63-1], anc[8], costing); // depth 5->6
|
||||
|
||||
LPXOR(m[61-1], m[62-1], l[0]);
|
||||
LPXOR(m[50-1], m[56-1], l[1]);
|
||||
|
@ -142,7 +148,7 @@ namespace BoyarPeralta11
|
|||
{
|
||||
body (...)
|
||||
{
|
||||
for (i in 1..n)
|
||||
for i in 1..n
|
||||
{
|
||||
T(input[0]);
|
||||
T(input[1]);
|
||||
|
@ -182,34 +188,61 @@ namespace BoyarPeralta11
|
|||
adjoint auto;
|
||||
}
|
||||
|
||||
operation SBox (input: Qubit[], output: Qubit[], costing: Bool) : Unit
|
||||
{
|
||||
body (...)
|
||||
{
|
||||
using ((t, m, l) = (Qubit[27], Qubit[63], Qubit[30]))
|
||||
{
|
||||
let u = input[7..(-1)..0];
|
||||
let s = output[7..(-1)..0];
|
||||
function SBoxAncCount() : Int {
|
||||
return 129;
|
||||
}
|
||||
|
||||
ForwardSBox(u, s, t, m, l, costing);
|
||||
|
||||
// get out result
|
||||
LPXOR(l[6], l[24], s[0]);
|
||||
LPXNOR(l[16], l[26], s[1]);
|
||||
LPXNOR(l[19], l[28], s[2]);
|
||||
LPXOR(l[6], l[21], s[3]);
|
||||
LPXOR(l[20], l[22], s[4]);
|
||||
LPXOR(l[25], l[29], s[5]);
|
||||
LPXNOR(l[13], l[27], s[6]);
|
||||
LPXNOR(l[6], l[23], s[7]);
|
||||
|
||||
// uncompute
|
||||
(Adjoint ForwardSBox)(u, s, t, m, l, costing);
|
||||
|
||||
// // dummy, forced-T-depth 2 s-box
|
||||
// DummySBox(input, output, 2);
|
||||
// Wrapper function for an SBox
|
||||
// Expects 129 qubits in ancAll, in the zeros state, and returns them to the zeros state
|
||||
// If there are fewer qubits, it will allocate more as needed
|
||||
operation SBox (input: Qubit[], output: Qubit[], ancAll: Qubit[], costing: Bool) : Unit {
|
||||
body (...){
|
||||
if Length(ancAll) < 129 {
|
||||
let nExtra = 129 - Length(ancAll);
|
||||
use extraAnc = Qubit[nExtra] {
|
||||
_SBox(input, output, ancAll + extraAnc, costing);
|
||||
}
|
||||
} else {
|
||||
_SBox(input, output, ancAll, costing);
|
||||
}
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
|
||||
|
||||
// Internal Sbox
|
||||
operation _SBox (input: Qubit[], output: Qubit[], ancAll: Qubit[], costing: Bool) : Unit
|
||||
{
|
||||
body (...)
|
||||
{
|
||||
// Bookkeeping
|
||||
let anc = Microsoft.Quantum.Arrays.Partitioned([27,63,30,9], ancAll);
|
||||
let t = anc[0];
|
||||
let m = anc[1];
|
||||
let l = anc[2];
|
||||
let ancAnd = anc[3];
|
||||
let u = input[7..(-1)..0];
|
||||
let s = output[7..(-1)..0];
|
||||
|
||||
ForwardSBox(u, s, t, m, l, ancAnd, costing);
|
||||
|
||||
// get out result
|
||||
LPXOR(l[6], l[24], s[0]);
|
||||
LPXNOR(l[16], l[26], s[1]);
|
||||
LPXNOR(l[19], l[28], s[2]);
|
||||
LPXOR(l[6], l[21], s[3]);
|
||||
LPXOR(l[20], l[22], s[4]);
|
||||
LPXOR(l[25], l[29], s[5]);
|
||||
LPXNOR(l[13], l[27], s[6]);
|
||||
LPXNOR(l[6], l[23], s[7]);
|
||||
|
||||
// uncompute
|
||||
(Adjoint ForwardSBox)(u, s, t, m, l, ancAnd, costing);
|
||||
|
||||
// // dummy, forced-T-depth 2 s-box
|
||||
// DummySBox(input, output, 2);
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
}
|
||||
|
|
136
aes/CSV.cs
136
aes/CSV.cs
|
@ -2,145 +2,15 @@
|
|||
// Licensed under the MIT license.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;
|
||||
|
||||
using FileHelpers; // csv parsing
|
||||
|
||||
// Library that deals with making human-friendly the CSV tracer's output
|
||||
|
||||
namespace cs
|
||||
namespace cswrapper
|
||||
{
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class DepthCounterCSV
|
||||
{
|
||||
public string Name;
|
||||
public string Variant;
|
||||
public string Caller;
|
||||
public string CallerVariant;
|
||||
public long Count;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal DepthAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal DepthSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal? DepthVariance;
|
||||
public long DepthSum;
|
||||
public long DepthMin;
|
||||
public long DepthMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal StartTimeAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal StartTimeSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))] // [FieldConverter(ConverterKind.Decimal, ".")]
|
||||
public decimal? StartTimeVariance;
|
||||
public long StartTimeSum;
|
||||
public long StartTimeMin;
|
||||
public long StartTimeMax;
|
||||
}
|
||||
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class WidthCounterCSV
|
||||
{
|
||||
public string Name;
|
||||
public string Variant;
|
||||
public string Caller;
|
||||
public string CallerVariant;
|
||||
public long Count;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthVariance;
|
||||
public long InputWidthSum;
|
||||
public long InputWidthMin;
|
||||
public long InputWidthMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthVariance;
|
||||
public long ExtraWidthSum;
|
||||
public long ExtraWidthMin;
|
||||
public long ExtraWidthMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthVariance;
|
||||
public long ReturnWidthSum;
|
||||
public long ReturnWidthMin;
|
||||
public long ReturnWidthMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthVariance;
|
||||
public long BorrowedWidthSum;
|
||||
public long BorrowedWidthMin;
|
||||
public long BorrowedWidthMax;
|
||||
}
|
||||
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class OperationCounterCSV
|
||||
{
|
||||
public string Name;
|
||||
public string Variant;
|
||||
public string Caller;
|
||||
public string CallerVariant;
|
||||
public long Count;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTVariance;
|
||||
public long CNOTSum;
|
||||
public long CNOTMin;
|
||||
public long CNOTMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordVariance;
|
||||
public long QubitCliffordSum;
|
||||
public long QubitCliffordMin;
|
||||
public long QubitCliffordMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RVariance;
|
||||
public long RSum;
|
||||
public long RMin;
|
||||
public long RMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureVariance;
|
||||
public long MeasureSum;
|
||||
public long MeasureMin;
|
||||
public long MeasureMax;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TAverage;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TSecondMoment;
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TVariance;
|
||||
public long TSum;
|
||||
public long TMin;
|
||||
public long TMax;
|
||||
}
|
||||
|
||||
public class QDecimalConverter : ConverterBase
|
||||
{
|
||||
|
@ -152,7 +22,7 @@ namespace cs
|
|||
}
|
||||
else
|
||||
{
|
||||
return Decimal.Parse(from);
|
||||
return Decimal.Parse(from, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
|
||||
}
|
||||
}
|
||||
public override string FieldToString(object fieldValue)
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Library that deals with making human-friendly the CSV tracer's output
|
||||
namespace cswrapper
|
||||
{
|
||||
using FileHelpers; // csv parsing
|
||||
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class DepthCounterCSV
|
||||
{
|
||||
public string Name
|
||||
{ get; set; }
|
||||
|
||||
public string Variant
|
||||
{ get; set; }
|
||||
|
||||
public string Caller
|
||||
{ get; set; }
|
||||
|
||||
public string CallerVariant
|
||||
{ get; set; }
|
||||
|
||||
public long Count
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal DepthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal DepthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal? DepthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long DepthSum
|
||||
{ get; set; }
|
||||
|
||||
public long DepthMin
|
||||
{ get; set; }
|
||||
|
||||
public long DepthMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal StartTimeDifferenceAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal StartTimeDifferenceSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))] // [FieldConverter(ConverterKind.Decimal, ".")]
|
||||
public decimal? StartTimeDifferenceVariance
|
||||
{ get; set; }
|
||||
|
||||
public long StartTimeDifferenceSum
|
||||
{ get; set; }
|
||||
|
||||
public long StartTimeDifferenceMin
|
||||
{ get; set; }
|
||||
|
||||
public long StartTimeDifferenceMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal WidthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal WidthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal? WidthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long WidthSum
|
||||
{ get; set; }
|
||||
|
||||
public long WidthMin
|
||||
{ get; set; }
|
||||
|
||||
public long WidthMax
|
||||
{ get; set; }
|
||||
}
|
||||
}
|
268
aes/Driver.cs
268
aes/Driver.cs
|
@ -5,152 +5,166 @@ using System;
|
|||
using Microsoft.Quantum.Simulation.Core;
|
||||
using Microsoft.Quantum.Simulation.Simulators;
|
||||
|
||||
namespace cs
|
||||
|
||||
namespace cswrapper
|
||||
{
|
||||
class Driver
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// estimating costs
|
||||
int NUMTESTS = 1;
|
||||
|
||||
bool free_swaps = true;
|
||||
for (int i=0; i < NUMTESTS; i++){
|
||||
Console.Write("operation, CNOT count, 1-qubit Clifford count, T count, R count, M count, T depth, initial width, extra width, comment, full depth");
|
||||
|
||||
Console.Write("operation, CNOT count, 1-qubit Clifford count, T count, R count, M count, T depth, initial width, extra width, comment, full depth");
|
||||
|
||||
// GF256
|
||||
Estimates.Mul<QGF256.Mul>("unrolled = false", false, free_swaps);
|
||||
Estimates.Mul<QGF256.UnrolledMul>("unrolled = true", true, free_swaps);
|
||||
Estimates.Square<QGF256.Square>("in_place = false", false, free_swaps);
|
||||
Estimates.Square<QGF256.InPlace.Square>("in_place = true", true, free_swaps);
|
||||
Estimates.Fourth<QGF256.Fourth>("in_place = false", false, free_swaps);
|
||||
Estimates.Fourth<QGF256.InPlace.Fourth>("in_place = true", true, free_swaps);
|
||||
Estimates.Sixteenth<QGF256.Sixteenth>("in_place = false", free_swaps);
|
||||
Estimates.SixtyFourth<QGF256.InPlace.SixtyFourth>("in_place = true", free_swaps);
|
||||
|
||||
// AES
|
||||
Estimates.SBox<GLRS16.SBox>("tower_field = false", false, false, free_swaps);
|
||||
// Estimates.SBox<NigelsSbox.SBox>("tower_field = true", true, free_swaps);
|
||||
Estimates.SBox<LPS19.SBox>("tower_field = true", true, true, free_swaps);
|
||||
Estimates.SBox<BoyarPeralta11.SBox>("tower_field = true", true, false, free_swaps);
|
||||
Estimates.ByteSub<QAES.ByteSub>("state size is the same for all", free_swaps);
|
||||
Estimates.ShiftRow<QAES.InPlace.ShiftRow>("in_place = true - state size is the same for all", free_swaps);
|
||||
Estimates.MixWord<QAES.InPlace.MixWord>("in_place = true", true, free_swaps);
|
||||
Estimates.MixWord<MaximovMixColumn.MixWord>("in_place = false", false, free_swaps);
|
||||
Estimates.MixColumn<QAES.InPlace.MixColumn>("widest = true - state size is the same for all", true, free_swaps);
|
||||
Estimates.MixColumn<MaximovMixColumn.MixColumn>("widest = false - state size is the same for all", false, free_swaps);
|
||||
Estimates.AddRoundKey<QAES.Widest.AddRoundKey>("widest = true - state size is the same for all", free_swaps);
|
||||
|
||||
// InPlace full KeyExpansion is never run as part of the algorithms, only for tests
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 10, Nk = 4", true, 10, 4, free_swaps);
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 12, Nk = 6", true, 12, 6, free_swaps);
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 14, Nk = 8", true, 14, 8, free_swaps);
|
||||
|
||||
// Partial key expansion is called for different sizes and in different rounds, and may have different values each time
|
||||
// AES 128
|
||||
for (int round = 1; round <= 10; round++)
|
||||
{
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk-1)$ - round {round}", 10, 4, round, 0, 3, free_swaps);
|
||||
}
|
||||
// AES 192
|
||||
for (int round = 1; round <= 12; round++)
|
||||
{
|
||||
if (round % 3 == 1)
|
||||
Estimates.DepthTest<QTests.GF256.MeasureDepth>();
|
||||
Estimates.AllOnesTest<QTests.GF256.TestAllOnes>();
|
||||
|
||||
// GF256
|
||||
Estimates.Mul<QGF256.Mul>("unrolled = false", false, free_swaps);
|
||||
Estimates.Mul<QGF256.UnrolledMul>("unrolled = true", true, free_swaps);
|
||||
Estimates.Square<QGF256.Square>("in_place = false", false, free_swaps);
|
||||
Estimates.Square<QGF256.InPlace.Square>("in_place = true", true, free_swaps);
|
||||
Estimates.Fourth<QGF256.Fourth>("in_place = false", false, free_swaps);
|
||||
Estimates.Fourth<QGF256.InPlace.Fourth>("in_place = true", true, free_swaps);
|
||||
Estimates.Sixteenth<QGF256.Sixteenth>("in_place = false", free_swaps);
|
||||
Estimates.SixtyFourth<QGF256.InPlace.SixtyFourth>("in_place = true", free_swaps);
|
||||
// AES
|
||||
Estimates.SBox<GLRS16.SBox>("tower_field = false", false, false, free_swaps);
|
||||
// for (int i = 0; i < NUMTESTS; i++) {
|
||||
// Estimates.SBox<NigelsSbox.SBox>("tower_field = true", true, free_swaps);
|
||||
// }
|
||||
Estimates.SBox<LPS19.SBox>("tower_field = true", true, true, free_swaps);
|
||||
Estimates.SBox<BoyarPeralta11.SBox>("tower_field = true", true, false, free_swaps);
|
||||
Estimates.ByteSub<QAES.ByteSub>("state size is the same for all", free_swaps);
|
||||
Estimates.MixWord<QAES.InPlace.MixWord>("in_place = true", true, free_swaps);
|
||||
Estimates.MixWord<MaximovMixColumn.MixWord>("in_place = false", false, free_swaps);
|
||||
Estimates.MixColumn<QAES.InPlace.MixColumn>("widest = true - state size is the same for all", true, free_swaps);
|
||||
Estimates.MixColumn<MaximovMixColumn.MixColumn>("widest = false - state size is the same for all", false, free_swaps);
|
||||
Estimates.AddRoundKey<QAES.Widest.AddRoundKey>("widest = true - state size is the same for all", free_swaps);
|
||||
// InPlace full KeyExpansion is never run as part of the algorithms, only for tests
|
||||
//
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 10, Nk = 4", true, 10, 4, free_swaps);
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 12, Nk = 6", true, 12, 6, free_swaps);
|
||||
// Estimates.KeyExpansion<QAES.InPlace.KeyExpansion>("in_place = true, Nr = 14, Nk = 8", true, 14, 8, free_swaps);
|
||||
// Partial key expansion is called for different sizes and in different rounds, and may have different values each time
|
||||
// AES 128
|
||||
for (int round = 1; round <= 10; round++)
|
||||
{
|
||||
int key_round = (round/3) * 2 + 1;
|
||||
if (round > 1)
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk-1)$ - round {round}", 10, 4, round, 0, 3, free_swaps);
|
||||
}
|
||||
// AES 192
|
||||
for (int round = 1; round <= 12; round++)
|
||||
{
|
||||
if (round % 3 == 1)
|
||||
{
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_(2*Nk/3)^(Nk-1)$ - round {round}", 12, 6, key_round, 4, 5, free_swaps);
|
||||
int key_round = (round/3) * 2 + 1;
|
||||
if (round > 1)
|
||||
{
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_(2*Nk/3)^(Nk-1)$ - round {round}", 12, 6, key_round, 4, 5, free_swaps);
|
||||
}
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk/3-1)$ - round {round}", 12, 6, key_round, 0, 1, free_swaps);
|
||||
}
|
||||
else if (round % 3 == 2)
|
||||
{
|
||||
int key_round = (round/3) * 2 + 1;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_2^(Nk-1)$ - round {round}", 12, 6, key_round, 2, 5, free_swaps);
|
||||
}
|
||||
else
|
||||
{
|
||||
int key_round = (round/3) * 2;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(2 Nk/3-1)$ - round {round}", 12, 6, key_round, 0, 3, free_swaps);
|
||||
}
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk/3-1)$ - round {round}", 12, 6, key_round, 0, 1, free_swaps);
|
||||
}
|
||||
else if (round % 3 == 2)
|
||||
// AES 256
|
||||
for (int round = 1; round <= 14; round++)
|
||||
{
|
||||
int key_round = (round/3) * 2 + 1;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_2^(Nk-1)$ - round {round}", 12, 6, key_round, 2, 5, free_swaps);
|
||||
}
|
||||
else
|
||||
{
|
||||
int key_round = (round/3) * 2;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(2 Nk/3-1)$ - round {round}", 12, 6, key_round, 0, 3, free_swaps);
|
||||
}
|
||||
}
|
||||
// AES 256
|
||||
for (int round = 1; round <= 14; round++)
|
||||
{
|
||||
if (round % 2 == 0)
|
||||
{
|
||||
int key_round = round/2;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk/2-1)$ - round {round}", 14, 8, key_round, 0, 3, free_swaps);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (round > 2)
|
||||
if (round % 2 == 0)
|
||||
{
|
||||
int key_round = round/2;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_(Nk/2)^(Nk-1)$ - round {round}", 14, 8, key_round, 4, 7, free_swaps);
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_0^(Nk/2-1)$ - round {round}", 14, 8, key_round, 0, 3, free_swaps);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (round > 2)
|
||||
{
|
||||
int key_round = round/2;
|
||||
Estimates.InPlacePartialKeyExpansion<QAES.InPlace.KeyExpansion>($"$KE_(Nk/2)^(Nk-1)$ - round {round}", 14, 8, key_round, 4, 7, free_swaps);
|
||||
}
|
||||
}
|
||||
}
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 10 - Nk = 4 - not currently used", false, 10, 4, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 12 - Nk = 6 - not currently used", false, 12, 6, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 14 - Nk = 8 - not currently used", false, 14, 8, free_swaps);
|
||||
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 10 - Nk = 4 - not currently used", false, 10, 4, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 12 - Nk = 6 - not currently used", false, 12, 6, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 14 - Nk = 8 - not currently used", false, 14, 8, free_swaps);
|
||||
|
||||
Estimates.Round<QAES.Widest.Round>("state size is the same for all", 0, false, 4, free_swaps);
|
||||
for (int round = 1; round <= 10; round++)
|
||||
{
|
||||
int Nk = 4;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
for (int round = 1; round <= 12; round++)
|
||||
{
|
||||
int Nk = 6;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
for (int round = 1; round <= 14; round++)
|
||||
{
|
||||
int Nk = 8;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
Estimates.FinalRound<QAES.Widest.FinalRound>("state size is the same for all", false, 4, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 4 - state size is the same for all but in-place expansion isn't", true, 4, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 6 - state size is the same for all but in-place expansion isn't", true, 6, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 8 - state size is the same for all but in-place expansion isn't", true, 8, free_swaps);
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 10 - Nk = 4", false, 10, 4, true, free_swaps, "_128_in-place-MC");
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 12 - Nk = 6", false, 12, 6, true, free_swaps, "_192_in-place-MC");
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 14 - Nk = 8", false, 14, 8, true, free_swaps, "_256_in-place-MC");
|
||||
bool widest = false;
|
||||
for (int ii=0; ii < 2; ii++){
|
||||
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 10 - Nk = 4 - in_place mixcolumn", widest, 10, 4, true, free_swaps, "_128_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 12 - Nk = 6 - in_place mixcolumn", widest, 12, 6, true, free_swaps, "_192_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 14 - Nk = 8 - in_place mixcolumn", widest, 14, 8, true, free_swaps, "_256_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 10 - Nk = 4 - Maximov's mixcolumn", widest, 10, 4, false, free_swaps, "_128_maximov-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 12 - Nk = 6 - Maximov's mixcolumn", widest, 12, 6, false, free_swaps, "_192_maximov-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>($"widest = {widest} - Nr = 14 - Nk = 8 - Maximov's mixcolumn", widest, 14, 8, false, free_swaps, "_256_maximov-MC");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 1", widest, 1, 10, 4, true, free_swaps, "_128_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 1", widest, 1, 12, 6, true, free_swaps, "_192_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 1", widest, 1, 14, 8, true, free_swaps, "_256_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 2", widest, 2, 10, 4, true, free_swaps, "_128_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 2", widest, 2, 12, 6, true, free_swaps, "_192_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 2", widest, 2, 14, 8, true, free_swaps, "_256_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 3", widest, 3, 10, 4, true, free_swaps, "_128_in-place-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 3", widest, 3, 12, 6, true, free_swaps, "_192_in-place-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 3", widest, 3, 14, 8, true, free_swaps, "_256_in-place-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 4", widest, 4, 12, 6, true, free_swaps, "_192_in-place-MC_r4");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 5", widest, 5, 14, 8, true, free_swaps, "_256_in-place-MC_r5");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 1", widest, 1, 10, 4, false, free_swaps, "_128_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 1", widest, 1, 12, 6, false, free_swaps, "_192_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 1", widest, 1, 14, 8, false, free_swaps, "_256_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 2", widest, 2, 10, 4, false, free_swaps, "_128_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 2", widest, 2, 12, 6, false, free_swaps, "_192_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 2", widest, 2, 14, 8, false, free_swaps, "_256_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 3", widest, 3, 10, 4, false, free_swaps, "_128_maximov-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 3", widest, 3, 12, 6, false, free_swaps, "_192_maximov-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 3", widest, 3, 14, 8, false, free_swaps, "_256_maximov-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 4", widest, 4, 12, 6, false, free_swaps, "_192_in-place-MC_r4");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>($"widest = {widest} - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 5", widest, 5, 14, 8, false, free_swaps, "_256_in-place-MC_r5");
|
||||
widest = true;
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 10 - Nk = 4 - not currently used", false, 10, 4, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 12 - Nk = 6 - not currently used", false, 12, 6, free_swaps);
|
||||
Estimates.KeyExpansion<QAES.Widest.KeyExpansion>("in_place = false - Nr = 14 - Nk = 8 - not currently used", false, 14, 8, free_swaps);
|
||||
|
||||
Estimates.Round<QAES.Widest.Round>("state size is the same for all", 0, false, 4, free_swaps);
|
||||
for (int round = 1; round <= 10; round++)
|
||||
{
|
||||
int Nk = 4;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
for (int round = 1; round <= 12; round++)
|
||||
{
|
||||
int Nk = 6;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
for (int round = 1; round <= 14; round++)
|
||||
{
|
||||
int Nk = 8;
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - in_place mixcolumn", round, true, Nk, true, free_swaps);
|
||||
Estimates.Round<QAES.SmartWide.Round>($"round = {round} - Nk = {Nk} - Maximov's mixcolumn", round, true, Nk, false, free_swaps);
|
||||
}
|
||||
Estimates.FinalRound<QAES.Widest.FinalRound>("state size is the same for all", false, 4, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 4 - state size is the same for all but in-place expansion isn't", true, 4, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 6 - state size is the same for all but in-place expansion isn't", true, 6, free_swaps);
|
||||
Estimates.FinalRound<QAES.SmartWide.FinalRound>("Nk = 8 - state size is the same for all but in-place expansion isn't", true, 8, free_swaps);
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 10 - Nk = 4 - in_place mixcolumn", true, 10, 4, true, free_swaps, "_128_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 12 - Nk = 6 - in_place mixcolumn", true, 12, 6, true, free_swaps, "_192_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 14 - Nk = 8 - in_place mixcolumn", true, 14, 8, true, free_swaps, "_256_in-place-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 10 - Nk = 4 - Maximov's mixcolumn", true, 10, 4, false, free_swaps, "_128_maximov-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 12 - Nk = 6 - Maximov's mixcolumn", true, 12, 6, false, free_swaps, "_192_maximov-MC");
|
||||
Estimates.Rijndael<QAES.SmartWide.Rijndael>("smart_wide = true - Nr = 14 - Nk = 8 - Maximov's mixcolumn", true, 14, 8, false, free_swaps, "_256_maximov-MC");
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 10 - Nk = 4", false, 10, 4, true, free_swaps, "_128_in-place-MC");
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 12 - Nk = 6", false, 12, 6, true, free_swaps, "_192_in-place-MC");
|
||||
Estimates.Rijndael<QAES.Widest.Rijndael>("smart_wide = false - Nr = 14 - Nk = 8", false, 14, 8, true, free_swaps, "_256_in-place-MC");
|
||||
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 1", true, 1, 10, 4, true, free_swaps, "_128_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 1", true, 1, 12, 6, true, free_swaps, "_192_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 1", true, 1, 14, 8, true, free_swaps, "_256_in-place-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 2", true, 2, 10, 4, true, free_swaps, "_128_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 2", true, 2, 12, 6, true, free_swaps, "_192_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 2", true, 2, 14, 8, true, free_swaps, "_256_in-place-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - in_place mixcolumn - r = 3", true, 3, 10, 4, true, free_swaps, "_128_in-place-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - in_place mixcolumn - r = 3", true, 3, 12, 6, true, free_swaps, "_192_in-place-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - in_place mixcolumn - r = 3", true, 3, 14, 8, true, free_swaps, "_256_in-place-MC_r3");
|
||||
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 1", true, 1, 10, 4, false, free_swaps, "_128_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 1", true, 1, 12, 6, false, free_swaps, "_192_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 1", true, 1, 14, 8, false, free_swaps, "_256_maximov-MC_r1");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 2", true, 2, 10, 4, false, free_swaps, "_128_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 2", true, 2, 12, 6, false, free_swaps, "_192_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 2", true, 2, 14, 8, false, free_swaps, "_256_maximov-MC_r2");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 10 - Nk = 4 - Maximov's mixcolumn - r = 3", true, 3, 10, 4, false, free_swaps, "_128_maximov-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 12 - Nk = 6 - Maximov's mixcolumn - r = 3", true, 3, 12, 6, false, free_swaps, "_192_maximov-MC_r3");
|
||||
Estimates.GroverOracle<QAES.SmartWide.GroverOracle>("smart_wide = true - Nr = 14 - Nk = 8 - Maximov's mixcolumn - r = 3", true, 3, 14, 8, false, free_swaps, "_256_maximov-MC_r3");
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
112
aes/Estimates.cs
112
aes/Estimates.cs
|
@ -2,32 +2,37 @@
|
|||
// Licensed under the MIT license.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Quantum.Simulation.Simulators;
|
||||
using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;
|
||||
using Microsoft.Quantum.Simulation.Core;
|
||||
using static Utilities;
|
||||
using FileHelpers; // csv parsing
|
||||
|
||||
namespace cs
|
||||
namespace cswrapper
|
||||
{
|
||||
class Estimates
|
||||
{
|
||||
static QCTraceSimulator getTraceSimulator(bool full_depth)
|
||||
{
|
||||
var config = new QCTraceSimulatorConfiguration();
|
||||
config.useDepthCounter = true;
|
||||
config.useWidthCounter = true;
|
||||
config.usePrimitiveOperationsCounter = true;
|
||||
config.throwOnUnconstraintMeasurement = false;
|
||||
|
||||
config.UseDepthCounter = true;
|
||||
config.UseWidthCounter = true;
|
||||
config.UsePrimitiveOperationsCounter = true;
|
||||
config.ThrowOnUnconstrainedMeasurement = false;
|
||||
config.OptimizeDepth = false;
|
||||
if (full_depth)
|
||||
{
|
||||
config.gateTimes[PrimitiveOperationsGroups.CNOT] = 1;
|
||||
config.gateTimes[PrimitiveOperationsGroups.Measure] = 1; // count all one and 2 qubit measurements as depth 1
|
||||
config.gateTimes[PrimitiveOperationsGroups.QubitClifford] = 1; // qubit Clifford depth 1
|
||||
config.TraceGateTimes[PrimitiveOperationsGroups.CNOT] = 1;
|
||||
config.TraceGateTimes[PrimitiveOperationsGroups.Measure] = 1; // count all one and 2 qubit measurements as depth 1
|
||||
config.TraceGateTimes[PrimitiveOperationsGroups.QubitClifford] = 1; // qubit Clifford depth 1
|
||||
config.TraceGateTimes[PrimitiveOperationsGroups.R] = 1; // rotations also get depth 1
|
||||
}
|
||||
return new QCTraceSimulator(config);
|
||||
return new ResourcesEstimator(config);
|
||||
// return new QCTraceSimulator(config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void ProcessSim<Qop>(QCTraceSimulator sim, string comment = "", bool full_depth = false, string suffix="")
|
||||
{
|
||||
if (!full_depth)
|
||||
|
@ -52,6 +57,25 @@ namespace cs
|
|||
}
|
||||
}
|
||||
|
||||
public static void DepthTest<Qop>()
|
||||
{
|
||||
var sim = getTraceSimulator(false);
|
||||
var res = QTests.GF256.MeasureDepth.Run(sim).Result;
|
||||
ProcessSim<Qop>(sim, "");
|
||||
sim = getTraceSimulator(true);
|
||||
res = QTests.GF256.MeasureDepth.Run(sim).Result;
|
||||
ProcessSim<Qop>(sim, "", true);
|
||||
}
|
||||
public static void AllOnesTest<Qop>()
|
||||
{
|
||||
var sim = getTraceSimulator(false);
|
||||
var res = QTests.GF256.TestAllOnes.Run(sim, 128, true).Result;
|
||||
ProcessSim<Qop>(sim, "");
|
||||
sim = getTraceSimulator(true);
|
||||
res = QTests.GF256.TestAllOnes.Run(sim, 128, true).Result;
|
||||
ProcessSim<Qop>(sim, "", true);
|
||||
}
|
||||
|
||||
public static void Mul<Qop>(string comment = "", bool unrolled = false, bool free_swaps = true)
|
||||
{
|
||||
var sim = getTraceSimulator(false);
|
||||
|
@ -226,51 +250,53 @@ namespace cs
|
|||
ProcessSim<Qop>(sim, comment, true);
|
||||
}
|
||||
|
||||
public static void Rijndael<Qop>(string comment = "", bool smart_wide = true, int Nr = 10, int Nk = 4, bool in_place_mixcolumn = true, bool free_swaps = true, string suffix = "")
|
||||
public static void Rijndael<Qop>(string comment = "", bool widest = false, int Nr = 10, int Nk = 4, bool in_place_mixcolumn = true, bool free_swaps = true, string suffix = "")
|
||||
{
|
||||
// var sparseSim = new ToffoliSimulator();
|
||||
// Random rand = new Random();
|
||||
// bool[] randomValues = new bool[128];
|
||||
|
||||
// for (int i = 0; i < 128; i++)
|
||||
// {
|
||||
// randomValues[i] = rand.Next(2) == 1;
|
||||
// }
|
||||
// QTests.AES.SmartWideRijndael.Run(sparseSim, BitsToQubits(randomValues), nQBits(32 * Nk, true), Nr, Nk, in_place_mixcolumn, widest, false);
|
||||
|
||||
var sim = getTraceSimulator(false);
|
||||
if (smart_wide)
|
||||
{
|
||||
var res = QTests.AES.SmartWideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, in_place_mixcolumn, free_swaps).Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var res = QTests.AES.WideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, true, free_swaps).Result;
|
||||
}
|
||||
var res = QTests.AES.SmartWideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, in_place_mixcolumn, widest, free_swaps).Result;
|
||||
ProcessSim<Qop>(sim, comment, false, suffix);
|
||||
sim = getTraceSimulator(true);
|
||||
if (smart_wide)
|
||||
{
|
||||
var res = QTests.AES.SmartWideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, in_place_mixcolumn, free_swaps).Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
var res = QTests.AES.WideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, true, free_swaps).Result;
|
||||
}
|
||||
res = QTests.AES.SmartWideRijndael.Run(sim, nQBits(128, false), nQBits(32 * Nk, false), Nr, Nk, in_place_mixcolumn, widest, free_swaps).Result;
|
||||
ProcessSim<Qop>(sim, comment, true);
|
||||
}
|
||||
|
||||
public static void GroverOracle<Qop>(string comment = "", bool smart_wide = true, int pairs = 1, int Nr = 10, int Nk = 4, bool in_place_mixcolumn = true, bool free_swaps = true, string suffix = "")
|
||||
public static void GroverOracle<Qop>(string comment = "", bool widest = false, int pairs = 1, int Nr = 10, int Nk = 4, bool in_place_mixcolumn = true, bool free_swaps = true, string suffix = "")
|
||||
{
|
||||
// var sparseSim = new ToffoliSimulator();
|
||||
// Random rand = new Random();
|
||||
// bool[] randomValues = new bool[32*Nk];
|
||||
|
||||
// for (int i = 0; i < 32*Nk; i++)
|
||||
// {
|
||||
// randomValues[i] = true;//rand.Next(2) == 1;
|
||||
// }
|
||||
// var res = QTests.AES.SmartWideGroverOracle.Run(sparseSim, BitsToQubits(randomValues), nQBits(128*pairs, false), nBits(128*pairs, false), pairs, Nr, Nk, in_place_mixcolumn, widest, false).Result;
|
||||
|
||||
var sim = getTraceSimulator(false);
|
||||
if (smart_wide)
|
||||
{
|
||||
var res = QTests.AES.SmartWideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128*pairs, false), nBits(128*pairs, false), pairs, Nr, Nk, in_place_mixcolumn, free_swaps).Result;
|
||||
}
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
var res = QTests.AES.SmartWideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128*pairs, false), nBits(128*pairs, false), pairs, Nr, Nk, in_place_mixcolumn, widest, free_swaps).Result;
|
||||
ProcessSim<Qop>(sim, comment, false, suffix);
|
||||
sim = getTraceSimulator(true);
|
||||
if (smart_wide)
|
||||
{
|
||||
var res = QTests.AES.SmartWideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128*pairs, false), nBits(128*pairs, false), pairs, Nr, Nk, in_place_mixcolumn, free_swaps).Result;
|
||||
}
|
||||
else
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
res = QTests.AES.SmartWideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128*pairs, false), nBits(128*pairs, false), pairs, Nr, Nk, in_place_mixcolumn, widest, free_swaps).Result;
|
||||
ProcessSim<Qop>(sim, comment, true);
|
||||
}
|
||||
// public static void WideGroverOracle<Qop>(string comment = "", int Nr = 10, int Nk = 4, bool free_swaps = true, string suffix = "")
|
||||
// {
|
||||
// var sim = getTraceSimulator(false);
|
||||
// var res = QTests.AES.WideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128, false), nBits(128, false), Nr, Nk, free_swaps).Result;
|
||||
// ProcessSim<Qop>(sim, comment, false, suffix);
|
||||
// sim = getTraceSimulator(true);
|
||||
// res = QTests.AES.WideGroverOracle.Run(sim, nQBits(32*Nk, false), nQBits(128, false), nBits(128, false), Nr, Nk, free_swaps).Result;
|
||||
// ProcessSim<Qop>(sim, comment, true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
587
aes/LPS19.qs
587
aes/LPS19.qs
|
@ -11,341 +11,342 @@ namespace LPS19
|
|||
{
|
||||
body (...)
|
||||
{
|
||||
CNOT(u[0], u[5]);
|
||||
CNOT(u[3], u[5]);
|
||||
CNOT(u[6], u[5]);
|
||||
CNOT(u[0], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[6], u[4]);
|
||||
LPAND(u[5], u[4], t[0], costing);
|
||||
CNOT(t[0], t[5]);
|
||||
use andAnc = Qubit[41] {
|
||||
CNOT(u[0], u[5]);
|
||||
CNOT(u[3], u[5]);
|
||||
CNOT(u[6], u[5]);
|
||||
CNOT(u[0], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[6], u[4]);
|
||||
LPANDWithAux(u[5], u[4], t[0], andAnc[0], costing);
|
||||
CNOT(t[0], t[5]);
|
||||
|
||||
CNOT(u[1], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[7], u[3]);
|
||||
LPAND(u[3], u[7], t[0], costing);
|
||||
CNOT(u[1], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[7], u[3]);
|
||||
LPANDWithAux(u[3], u[7], t[0], andAnc[1], costing);
|
||||
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[0], u[2]);
|
||||
CNOT(u[4], u[2]);
|
||||
CNOT(u[5], u[2]);
|
||||
CNOT(u[6], u[2]);
|
||||
LPAND(u[6], u[2], t[1], costing);
|
||||
CNOT(t[1], t[2]);
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[0], u[2]);
|
||||
CNOT(u[4], u[2]);
|
||||
CNOT(u[5], u[2]);
|
||||
CNOT(u[6], u[2]);
|
||||
LPANDWithAux(u[6], u[2], t[1], andAnc[2], costing);
|
||||
CNOT(t[1], t[2]);
|
||||
|
||||
CNOT(u[2], u[1]);
|
||||
CNOT(u[4], u[1]);
|
||||
CNOT(u[5], u[1]);
|
||||
CNOT(u[7], u[1]);
|
||||
CNOT(u[1], u[0]);
|
||||
CNOT(u[6], u[0]);
|
||||
LPAND(u[1], u[0], t[1], costing);
|
||||
CNOT(u[2], u[1]);
|
||||
CNOT(u[4], u[1]);
|
||||
CNOT(u[5], u[1]);
|
||||
CNOT(u[7], u[1]);
|
||||
CNOT(u[1], u[0]);
|
||||
CNOT(u[6], u[0]);
|
||||
LPANDWithAux(u[1], u[0], t[1], andAnc[3], costing);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[0], u[2]);
|
||||
LPAND(u[6], u[2], t[2], costing);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[0], u[2]);
|
||||
LPANDWithAux(u[6], u[2], t[2], andAnc[4], costing);
|
||||
|
||||
CNOT(u[6], u[3]);
|
||||
CNOT(u[7], u[2]);
|
||||
LPAND(u[3], u[2], t[3], costing);
|
||||
CNOT(t[3], t[4]);
|
||||
CNOT(u[6], u[3]);
|
||||
CNOT(u[7], u[2]);
|
||||
LPANDWithAux(u[3], u[2], t[3], andAnc[5], costing);
|
||||
CNOT(t[3], t[4]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[2], u[0]);
|
||||
CNOT(u[4], u[0]);
|
||||
CNOT(u[7], u[0]);
|
||||
LPAND(u[6], u[0], t[3], costing);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[2], u[0]);
|
||||
CNOT(u[4], u[0]);
|
||||
CNOT(u[7], u[0]);
|
||||
LPANDWithAux(u[6], u[0], t[3], andAnc[6], costing);
|
||||
|
||||
CNOT(u[6], u[3]);
|
||||
CNOT(u[2], u[0]);
|
||||
LPAND(u[3], u[0], t[4], costing);
|
||||
CNOT(u[6], u[3]);
|
||||
CNOT(u[2], u[0]);
|
||||
LPANDWithAux(u[3], u[0], t[4], andAnc[7], costing);
|
||||
|
||||
CNOT(t[3], t[1]);
|
||||
CNOT(t[3], t[1]);
|
||||
|
||||
CNOT(u[1], u[3]);
|
||||
CNOT(u[7], u[4]);
|
||||
LPAND(u[3], u[4], t[5], costing);
|
||||
CNOT(u[1], u[3]);
|
||||
CNOT(u[7], u[4]);
|
||||
LPANDWithAux(u[3], u[4], t[5], andAnc[8], costing);
|
||||
|
||||
CNOT(t[5], t[3]);
|
||||
CNOT(t[5], t[3]);
|
||||
|
||||
CNOT(t[4], t[0]);
|
||||
CNOT(t[4], t[0]);
|
||||
|
||||
CNOT(t[2], t[4]);
|
||||
CNOT(t[2], t[4]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[6], t[3]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[6], t[3]);
|
||||
|
||||
CNOT(u[0], u[1]);
|
||||
CNOT(u[3], u[1]);
|
||||
CNOT(u[1], t[0]);
|
||||
CNOT(u[0], u[1]);
|
||||
CNOT(u[3], u[1]);
|
||||
CNOT(u[1], t[0]);
|
||||
|
||||
CNOT(u[1], u[5]);
|
||||
CNOT(u[4], u[5]);
|
||||
CNOT(u[6], u[5]);
|
||||
CNOT(u[7], u[5]);
|
||||
CNOT(u[5], t[1]);
|
||||
CNOT(u[1], u[5]);
|
||||
CNOT(u[4], u[5]);
|
||||
CNOT(u[6], u[5]);
|
||||
CNOT(u[7], u[5]);
|
||||
CNOT(u[5], t[1]);
|
||||
|
||||
CNOT(u[1], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[5], u[4]);
|
||||
CNOT(u[4], t[4]);
|
||||
CNOT(u[1], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[5], u[4]);
|
||||
CNOT(u[4], t[4]);
|
||||
|
||||
LPAND(t[3], t[1], t[6], costing);
|
||||
CNOT(t[0], t[3]);
|
||||
LPANDWithAux(t[3], t[1], t[6], andAnc[9], costing);
|
||||
CNOT(t[0], t[3]);
|
||||
|
||||
CNOT(t[4], t[7]);
|
||||
CNOT(t[6], t[7]);
|
||||
CNOT(t[4], t[7]);
|
||||
CNOT(t[6], t[7]);
|
||||
|
||||
CNOT(t[0], t[6]);
|
||||
LPAND(t[3], t[7], t[0], costing);
|
||||
CNOT(t[0], t[6]);
|
||||
LPANDWithAux(t[3], t[7], t[0], andAnc[10], costing);
|
||||
|
||||
CNOT(t[1], t[8]);
|
||||
CNOT(t[4], t[8]);
|
||||
CNOT(t[1], t[8]);
|
||||
CNOT(t[4], t[8]);
|
||||
|
||||
LPAND(t[6], t[8], t[9], costing);
|
||||
LPANDWithAux(t[6], t[8], t[9], andAnc[11], costing);
|
||||
|
||||
|
||||
CNOT(t[4], t[8]);
|
||||
CNOT(t[1], t[8]);
|
||||
CNOT(t[4], t[8]);
|
||||
CNOT(t[1], t[8]);
|
||||
|
||||
|
||||
CNOT(t[4], t[9]);
|
||||
CNOT(t[9], t[1]);
|
||||
CNOT(t[4], t[9]);
|
||||
CNOT(t[9], t[1]);
|
||||
|
||||
CNOT(t[7], t[8]);
|
||||
CNOT(t[9], t[8]);
|
||||
CNOT(t[7], t[8]);
|
||||
CNOT(t[9], t[8]);
|
||||
|
||||
LPAND(t[4], t[8], t[10], costing);
|
||||
LPANDWithAux(t[4], t[8], t[10], andAnc[12], costing);
|
||||
|
||||
|
||||
CNOT(t[9], t[8]);
|
||||
CNOT(t[7], t[8]);
|
||||
CNOT(t[9], t[8]);
|
||||
CNOT(t[7], t[8]);
|
||||
|
||||
|
||||
CNOT(t[10], t[1]);
|
||||
CNOT(t[10], t[7]);
|
||||
LPAND(t[0], t[7], t[3], costing);
|
||||
CNOT(t[10], t[1]);
|
||||
CNOT(t[10], t[7]);
|
||||
LPANDWithAux(t[0], t[7], t[3], andAnc[13], costing);
|
||||
|
||||
CNOT(t[3], t[8]);
|
||||
CNOT(t[1], t[8]);
|
||||
CNOT(t[3], t[8]);
|
||||
CNOT(t[1], t[8]);
|
||||
|
||||
CNOT(t[0], t[11]);
|
||||
CNOT(t[9], t[11]);
|
||||
CNOT(t[0], t[11]);
|
||||
CNOT(t[9], t[11]);
|
||||
|
||||
|
||||
CNOT(t[0], t[12]);
|
||||
CNOT(t[3], t[12]);
|
||||
CNOT(t[0], t[12]);
|
||||
CNOT(t[3], t[12]);
|
||||
|
||||
CNOT(t[9], t[13]);
|
||||
CNOT(t[1], t[13]);
|
||||
CNOT(t[9], t[13]);
|
||||
CNOT(t[1], t[13]);
|
||||
|
||||
CNOT(t[11], t[14]);
|
||||
CNOT(t[8], t[14]);
|
||||
CNOT(t[11], t[14]);
|
||||
CNOT(t[8], t[14]);
|
||||
|
||||
CNOT(u[0], u[2]);
|
||||
CNOT(u[1], u[2]);
|
||||
CNOT(u[6], u[2]);
|
||||
CNOT(u[0], u[2]);
|
||||
CNOT(u[1], u[2]);
|
||||
CNOT(u[6], u[2]);
|
||||
|
||||
CNOT(u[1], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[5], u[4]);
|
||||
CNOT(u[1], u[4]);
|
||||
CNOT(u[3], u[4]);
|
||||
CNOT(u[5], u[4]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[7], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[7], u[6]);
|
||||
|
||||
CNOT(u[1], u[0]);
|
||||
CNOT(u[3], u[0]);
|
||||
CNOT(u[1], u[0]);
|
||||
CNOT(u[3], u[0]);
|
||||
|
||||
CNOT(u[0], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[6], u[3]);
|
||||
CNOT(u[0], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[6], u[3]);
|
||||
|
||||
LPAND(t[0], u[3], s[2], costing);
|
||||
CNOT(s[2], s[5]);
|
||||
|
||||
CNOT(u[0], u[3]);
|
||||
LPAND(t[12], u[3], s[6], costing);
|
||||
CNOT(s[6], s[2]);
|
||||
CNOT(s[6], s[5]);
|
||||
CNOT(u[0], u[3]);
|
||||
|
||||
LPAND(t[1], u[4], s[1], costing);
|
||||
CNOT(s[1], s[3]);
|
||||
CNOT(s[1], s[4]);
|
||||
CNOT(u[7], u[4]);
|
||||
LPAND(t[13], u[4], s[7], costing);
|
||||
CNOT(s[7], s[1]);
|
||||
CNOT(s[7], s[2]);
|
||||
CNOT(s[7], s[3]);
|
||||
CNOT(s[7], s[5]);
|
||||
CNOT(u[7], u[4]);
|
||||
|
||||
LPAND(t[3], u[0], s[6], costing);
|
||||
CNOT(s[6], s[7]);
|
||||
|
||||
CNOT(u[3], u[6]);
|
||||
LPAND(t[11], u[6], s[0], costing);
|
||||
CNOT(s[0], s[2]);
|
||||
CNOT(u[3], u[6]);
|
||||
|
||||
LPAND(t[14], u[2], s[0], costing);
|
||||
CNOT(s[0], s[1]);
|
||||
CNOT(s[0], s[3]);
|
||||
CNOT(s[0], s[4]);
|
||||
CNOT(s[0], s[5]);
|
||||
CNOT(s[0], s[6]);
|
||||
CNOT(s[0], s[7]);
|
||||
|
||||
LPAND(t[9], u[7], z[0], costing);
|
||||
CNOT(z[0], s[2]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[7]);
|
||||
LPAND(t[9], u[7], z[0], costing);
|
||||
|
||||
CNOT(u[0], u[5]);
|
||||
CNOT(u[3], u[5]);
|
||||
LPAND(t[12], u[5], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[7]);
|
||||
|
||||
LPAND(t[12], u[5], z[0], costing);
|
||||
CNOT(u[3], u[5]);
|
||||
CNOT(u[0], u[5]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
LPAND(t[3], u[6], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPAND(t[3], u[6], z[0], costing);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
LPAND(t[0], u[6], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[6]);
|
||||
CNOT(z[0], s[7]);
|
||||
|
||||
LPAND(t[0], u[6], z[0], costing);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[0], u[6]);
|
||||
|
||||
CNOT(u[0], u[7]);
|
||||
CNOT(u[1], u[7]);
|
||||
CNOT(u[2], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[6], u[7]);
|
||||
LPAND(t[11], u[7], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[2]);
|
||||
|
||||
LPAND(t[11], u[7], z[0], costing);
|
||||
CNOT(u[6], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[2], u[7]);
|
||||
CNOT(u[1], u[7]);
|
||||
CNOT(u[0], u[7]);
|
||||
|
||||
CNOT(u[0], u[7]);
|
||||
CNOT(u[3], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
LPAND(t[14], u[7], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPAND(t[14], u[7], z[0], costing);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[3], u[7]);
|
||||
CNOT(u[0], u[7]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPAND(t[8], u[6], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[2]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPAND(t[8], u[6], z[0], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
|
||||
CNOT(u[0], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
LPAND(t[13], u[3], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
|
||||
LPAND(t[13], u[3], z[0], costing);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[0], u[3]);
|
||||
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPAND(t[1], u[6], z[0], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
|
||||
LPAND(t[1], u[6], z[0], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[0], u[6]);
|
||||
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPAND(t[8], u[6], s[2], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
|
||||
LPAND(t[9], u[6], s[5], costing);
|
||||
LPANDWithAux(t[0], u[3], s[2], andAnc[14], costing);
|
||||
CNOT(s[2], s[5]);
|
||||
|
||||
CNOT(u[0], u[3]);
|
||||
LPANDWithAux(t[12], u[3], s[6], andAnc[15], costing);
|
||||
CNOT(s[6], s[2]);
|
||||
CNOT(s[6], s[5]);
|
||||
CNOT(u[0], u[3]);
|
||||
|
||||
LPANDWithAux(t[1], u[4], s[1], andAnc[16], costing);
|
||||
CNOT(s[1], s[3]);
|
||||
CNOT(s[1], s[4]);
|
||||
CNOT(u[7], u[4]);
|
||||
LPANDWithAux(t[13], u[4], s[7], andAnc[17], costing);
|
||||
CNOT(s[7], s[1]);
|
||||
CNOT(s[7], s[2]);
|
||||
CNOT(s[7], s[3]);
|
||||
CNOT(s[7], s[5]);
|
||||
CNOT(u[7], u[4]);
|
||||
|
||||
LPANDWithAux(t[3], u[0], s[6], andAnc[18], costing);
|
||||
CNOT(s[6], s[7]);
|
||||
|
||||
CNOT(u[3], u[6]);
|
||||
LPANDWithAux(t[11], u[6], s[0], andAnc[19], costing);
|
||||
CNOT(s[0], s[2]);
|
||||
CNOT(u[3], u[6]);
|
||||
|
||||
LPANDWithAux(t[14], u[2], s[0], andAnc[20], costing);
|
||||
CNOT(s[0], s[1]);
|
||||
CNOT(s[0], s[3]);
|
||||
CNOT(s[0], s[4]);
|
||||
CNOT(s[0], s[5]);
|
||||
CNOT(s[0], s[6]);
|
||||
CNOT(s[0], s[7]);
|
||||
|
||||
LPANDWithAux(t[9], u[7], z[0], andAnc[21], costing);
|
||||
CNOT(z[0], s[2]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[7]);
|
||||
LPANDWithAux(t[9], u[7], z[0], andAnc[22], costing);
|
||||
|
||||
CNOT(u[0], u[5]);
|
||||
CNOT(u[3], u[5]);
|
||||
LPANDWithAux(t[12], u[5], z[0], andAnc[23], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[7]);
|
||||
|
||||
LPANDWithAux(t[12], u[5], z[0], andAnc[24], costing);
|
||||
CNOT(u[3], u[5]);
|
||||
CNOT(u[0], u[5]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
LPANDWithAux(t[3], u[6], z[0], andAnc[25], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPANDWithAux(t[3], u[6], z[0], andAnc[26], costing);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[5], u[6]);
|
||||
LPANDWithAux(t[0], u[6], z[0], andAnc[27], costing);
|
||||
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[6]);
|
||||
CNOT(z[0], s[7]);
|
||||
|
||||
LPANDWithAux(t[0], u[6], z[0], andAnc[28], costing);
|
||||
CNOT(u[5], u[6]);
|
||||
CNOT(u[4], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[0], u[6]);
|
||||
|
||||
CNOT(u[0], u[7]);
|
||||
CNOT(u[1], u[7]);
|
||||
CNOT(u[2], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[6], u[7]);
|
||||
LPANDWithAux(t[11], u[7], z[0], andAnc[29], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[2]);
|
||||
|
||||
LPANDWithAux(t[11], u[7], z[0], andAnc[30], costing);
|
||||
CNOT(u[6], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[2], u[7]);
|
||||
CNOT(u[1], u[7]);
|
||||
CNOT(u[0], u[7]);
|
||||
|
||||
CNOT(u[0], u[7]);
|
||||
CNOT(u[3], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[5], u[7]);
|
||||
LPANDWithAux(t[14], u[7], z[0], andAnc[31], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPANDWithAux(t[14], u[7], z[0], andAnc[32], costing);
|
||||
CNOT(u[5], u[7]);
|
||||
CNOT(u[4], u[7]);
|
||||
CNOT(u[3], u[7]);
|
||||
CNOT(u[0], u[7]);
|
||||
|
||||
CNOT(u[1], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPANDWithAux(t[8], u[6], z[0], andAnc[33], costing);
|
||||
|
||||
CNOT(z[0], s[2]);
|
||||
CNOT(z[0], s[5]);
|
||||
CNOT(z[0], s[6]);
|
||||
|
||||
LPANDWithAux(t[8], u[6], z[0], andAnc[34], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[1], u[6]);
|
||||
|
||||
CNOT(u[0], u[3]);
|
||||
CNOT(u[2], u[3]);
|
||||
LPANDWithAux(t[13], u[3], z[0], andAnc[35], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
|
||||
LPANDWithAux(t[13], u[3], z[0], andAnc[36], costing);
|
||||
CNOT(u[2], u[3]);
|
||||
CNOT(u[0], u[3]);
|
||||
|
||||
CNOT(u[0], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPANDWithAux(t[1], u[6], z[0], andAnc[37], costing);
|
||||
|
||||
CNOT(z[0], s[0]);
|
||||
CNOT(z[0], s[1]);
|
||||
CNOT(z[0], s[3]);
|
||||
CNOT(z[0], s[4]);
|
||||
CNOT(z[0], s[5]);
|
||||
|
||||
LPANDWithAux(t[1], u[6], z[0], andAnc[38], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[0], u[6]);
|
||||
|
||||
CNOT(u[2], u[6]);
|
||||
CNOT(u[3], u[6]);
|
||||
LPANDWithAux(t[8], u[6], s[2], andAnc[39], costing);
|
||||
CNOT(u[3], u[6]);
|
||||
CNOT(u[2], u[6]);
|
||||
|
||||
LPANDWithAux(t[9], u[6], s[5], andAnc[40], costing);
|
||||
}
|
||||
X(s[1]);
|
||||
X(s[2]);
|
||||
X(s[6]);
|
||||
|
@ -358,13 +359,13 @@ namespace LPS19
|
|||
{
|
||||
body (...)
|
||||
{
|
||||
using ((t, z, s) = (Qubit[15], Qubit[1], Qubit[8]))
|
||||
use (t, z, s) = (Qubit[15], Qubit[1], Qubit[8])
|
||||
{
|
||||
let u = input[7..(-1)..0];
|
||||
|
||||
ForwardSBox(u, t, z, s, costing);
|
||||
|
||||
for (i in 0..7)
|
||||
for i in 0..7
|
||||
{
|
||||
CNOT(s[i], output[7-i]);
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MaximovMixColumn
|
|||
{
|
||||
body (...)
|
||||
{
|
||||
for (j in first_word..last_word)
|
||||
for j in first_word..last_word
|
||||
{
|
||||
MixWord(in_state[j], out_state[j]);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace MaximovMixColumn
|
|||
// LPXOR(\3[\4], \5[\6], \1[\2]);
|
||||
body (...)
|
||||
{
|
||||
using (t = Qubit[62])
|
||||
use t = Qubit[62]
|
||||
{
|
||||
LPXOR(x[15], x[23], t[0]);
|
||||
LPXOR(x[7], x[31], t[1]);
|
||||
|
@ -129,7 +129,7 @@ namespace MaximovMixColumn
|
|||
LPXOR(t[59], t[61], y[28]);
|
||||
|
||||
// now need to cleanup the t array
|
||||
// everything is an XOR, fine not using Adjoint decorator
|
||||
// everything is an XOR, fine not use Adjoint decorator
|
||||
LPXOR(y[20], t[58], t[61]);
|
||||
LPXOR(x[4], t[10], t[60]);
|
||||
LPXOR(t[31], t[32], t[59]);
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Library that deals with making human-friendly the CSV tracer's output
|
||||
namespace cswrapper
|
||||
{
|
||||
using FileHelpers; // csv parsing
|
||||
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class OperationCounterCSV
|
||||
{
|
||||
public string Name
|
||||
{ get; set; }
|
||||
|
||||
public string Variant
|
||||
{ get; set; }
|
||||
|
||||
public string Caller
|
||||
{ get; set; }
|
||||
|
||||
public string CallerVariant
|
||||
{ get; set; }
|
||||
|
||||
public long Count
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal CNOTVariance
|
||||
{ get; set; }
|
||||
|
||||
public long CNOTSum
|
||||
{ get; set; }
|
||||
|
||||
public long CNOTMin
|
||||
{ get; set; }
|
||||
|
||||
public long CNOTMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal QubitCliffordVariance
|
||||
{ get; set; }
|
||||
|
||||
public long QubitCliffordSum
|
||||
{ get; set; }
|
||||
|
||||
public long QubitCliffordMin
|
||||
{ get; set; }
|
||||
|
||||
public long QubitCliffordMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal RVariance
|
||||
{ get; set; }
|
||||
|
||||
public long RSum
|
||||
{ get; set; }
|
||||
|
||||
public long RMin
|
||||
{ get; set; }
|
||||
|
||||
public long RMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal MeasureVariance
|
||||
{ get; set; }
|
||||
|
||||
public long MeasureSum
|
||||
{ get; set; }
|
||||
|
||||
public long MeasureMin
|
||||
{ get; set; }
|
||||
|
||||
public long MeasureMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal TVariance
|
||||
{ get; set; }
|
||||
|
||||
public long TSum
|
||||
{ get; set; }
|
||||
|
||||
public long TMin
|
||||
{ get; set; }
|
||||
|
||||
public long TMax
|
||||
{ get; set; }
|
||||
}
|
||||
}
|
765
aes/QAES.qs
765
aes/QAES.qs
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
142
aes/QGF256.qs
142
aes/QGF256.qs
|
@ -18,11 +18,11 @@ namespace QGF256
|
|||
body (...)
|
||||
{
|
||||
// construct e
|
||||
for (i in 0..6)
|
||||
for i in 0..6
|
||||
{
|
||||
for (j in (i+1)..7)
|
||||
for j in (i+1)..7
|
||||
{
|
||||
ccnot(a[j], b[8+i-j], res[i], costing);
|
||||
ccnot(a[j], b[8+i-j], res[i], [], costing);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,11 +61,11 @@ namespace QGF256
|
|||
CNOT(res[0], res[1]);
|
||||
|
||||
// compute d
|
||||
for (i in 0..7)
|
||||
for i in 0..7
|
||||
{
|
||||
for (j in 0..i)
|
||||
for j in 0..i
|
||||
{
|
||||
ccnot(a[j], b[i-j], res[i], costing);
|
||||
ccnot(a[j], b[i-j], res[i], [], costing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,40 +87,40 @@ namespace QGF256
|
|||
{
|
||||
// construct e
|
||||
|
||||
ccnot(a[1], b[7], res[0], costing);
|
||||
ccnot(a[2], b[6], res[0], costing);
|
||||
ccnot(a[3], b[5], res[0], costing);
|
||||
ccnot(a[4], b[4], res[0], costing);
|
||||
ccnot(a[5], b[3], res[0], costing);
|
||||
ccnot(a[6], b[2], res[0], costing);
|
||||
ccnot(a[7], b[1], res[0], costing);
|
||||
ccnot(a[1], b[7], res[0], [], costing);
|
||||
ccnot(a[2], b[6], res[0], [], costing);
|
||||
ccnot(a[3], b[5], res[0], [], costing);
|
||||
ccnot(a[4], b[4], res[0], [], costing);
|
||||
ccnot(a[5], b[3], res[0], [], costing);
|
||||
ccnot(a[6], b[2], res[0], [], costing);
|
||||
ccnot(a[7], b[1], res[0], [], costing);
|
||||
|
||||
ccnot(a[2], b[7], res[1], costing);
|
||||
ccnot(a[3], b[6], res[1], costing);
|
||||
ccnot(a[4], b[5], res[1], costing);
|
||||
ccnot(a[5], b[4], res[1], costing);
|
||||
ccnot(a[6], b[3], res[1], costing);
|
||||
ccnot(a[7], b[2], res[1], costing);
|
||||
ccnot(a[2], b[7], res[1], [], costing);
|
||||
ccnot(a[3], b[6], res[1], [], costing);
|
||||
ccnot(a[4], b[5], res[1], [], costing);
|
||||
ccnot(a[5], b[4], res[1], [], costing);
|
||||
ccnot(a[6], b[3], res[1], [], costing);
|
||||
ccnot(a[7], b[2], res[1], [], costing);
|
||||
|
||||
ccnot(a[3], b[7], res[2], costing);
|
||||
ccnot(a[4], b[6], res[2], costing);
|
||||
ccnot(a[5], b[5], res[2], costing);
|
||||
ccnot(a[6], b[4], res[2], costing);
|
||||
ccnot(a[7], b[3], res[2], costing);
|
||||
ccnot(a[3], b[7], res[2], [], costing);
|
||||
ccnot(a[4], b[6], res[2], [], costing);
|
||||
ccnot(a[5], b[5], res[2], [], costing);
|
||||
ccnot(a[6], b[4], res[2], [], costing);
|
||||
ccnot(a[7], b[3], res[2], [], costing);
|
||||
|
||||
ccnot(a[4], b[7], res[3], costing);
|
||||
ccnot(a[5], b[6], res[3], costing);
|
||||
ccnot(a[6], b[5], res[3], costing);
|
||||
ccnot(a[7], b[4], res[3], costing);
|
||||
ccnot(a[4], b[7], res[3], [], costing);
|
||||
ccnot(a[5], b[6], res[3], [], costing);
|
||||
ccnot(a[6], b[5], res[3], [], costing);
|
||||
ccnot(a[7], b[4], res[3], [], costing);
|
||||
|
||||
ccnot(a[5], b[7], res[4], costing);
|
||||
ccnot(a[6], b[6], res[4], costing);
|
||||
ccnot(a[7], b[5], res[4], costing);
|
||||
ccnot(a[5], b[7], res[4], [], costing);
|
||||
ccnot(a[6], b[6], res[4], [], costing);
|
||||
ccnot(a[7], b[5], res[4], [], costing);
|
||||
|
||||
ccnot(a[6], b[7], res[5], costing);
|
||||
ccnot(a[7], b[6], res[5], costing);
|
||||
ccnot(a[6], b[7], res[5], [], costing);
|
||||
ccnot(a[7], b[6], res[5], [], costing);
|
||||
|
||||
ccnot(a[7], b[7], res[6], costing);
|
||||
ccnot(a[7], b[7], res[6], [], costing);
|
||||
|
||||
// do modulo reduction
|
||||
// U
|
||||
|
@ -158,49 +158,49 @@ namespace QGF256
|
|||
|
||||
// compute d
|
||||
|
||||
ccnot(a[0], b[7], res[7], costing);
|
||||
ccnot(a[1], b[6], res[7], costing);
|
||||
ccnot(a[2], b[5], res[7], costing);
|
||||
ccnot(a[3], b[4], res[7], costing);
|
||||
ccnot(a[4], b[3], res[7], costing);
|
||||
ccnot(a[5], b[2], res[7], costing);
|
||||
ccnot(a[6], b[1], res[7], costing);
|
||||
ccnot(a[7], b[0], res[7], costing);
|
||||
ccnot(a[0], b[7], res[7], [], costing);
|
||||
ccnot(a[1], b[6], res[7], [], costing);
|
||||
ccnot(a[2], b[5], res[7], [], costing);
|
||||
ccnot(a[3], b[4], res[7], [], costing);
|
||||
ccnot(a[4], b[3], res[7], [], costing);
|
||||
ccnot(a[5], b[2], res[7], [], costing);
|
||||
ccnot(a[6], b[1], res[7], [], costing);
|
||||
ccnot(a[7], b[0], res[7], [], costing);
|
||||
|
||||
ccnot(a[0], b[6], res[6], costing);
|
||||
ccnot(a[1], b[5], res[6], costing);
|
||||
ccnot(a[2], b[4], res[6], costing);
|
||||
ccnot(a[3], b[3], res[6], costing);
|
||||
ccnot(a[4], b[2], res[6], costing);
|
||||
ccnot(a[5], b[1], res[6], costing);
|
||||
ccnot(a[6], b[0], res[6], costing);
|
||||
ccnot(a[0], b[6], res[6], [], costing);
|
||||
ccnot(a[1], b[5], res[6], [], costing);
|
||||
ccnot(a[2], b[4], res[6], [], costing);
|
||||
ccnot(a[3], b[3], res[6], [], costing);
|
||||
ccnot(a[4], b[2], res[6], [], costing);
|
||||
ccnot(a[5], b[1], res[6], [], costing);
|
||||
ccnot(a[6], b[0], res[6], [], costing);
|
||||
|
||||
ccnot(a[0], b[5], res[5], costing);
|
||||
ccnot(a[1], b[4], res[5], costing);
|
||||
ccnot(a[2], b[3], res[5], costing);
|
||||
ccnot(a[3], b[2], res[5], costing);
|
||||
ccnot(a[4], b[1], res[5], costing);
|
||||
ccnot(a[5], b[0], res[5], costing);
|
||||
ccnot(a[0], b[5], res[5], [], costing);
|
||||
ccnot(a[1], b[4], res[5], [], costing);
|
||||
ccnot(a[2], b[3], res[5], [], costing);
|
||||
ccnot(a[3], b[2], res[5], [], costing);
|
||||
ccnot(a[4], b[1], res[5], [], costing);
|
||||
ccnot(a[5], b[0], res[5], [], costing);
|
||||
|
||||
ccnot(a[0], b[4], res[4], costing);
|
||||
ccnot(a[1], b[3], res[4], costing);
|
||||
ccnot(a[2], b[2], res[4], costing);
|
||||
ccnot(a[3], b[1], res[4], costing);
|
||||
ccnot(a[4], b[0], res[4], costing);
|
||||
ccnot(a[0], b[4], res[4], [], costing);
|
||||
ccnot(a[1], b[3], res[4], [], costing);
|
||||
ccnot(a[2], b[2], res[4], [], costing);
|
||||
ccnot(a[3], b[1], res[4], [], costing);
|
||||
ccnot(a[4], b[0], res[4], [], costing);
|
||||
|
||||
ccnot(a[0], b[3], res[3], costing);
|
||||
ccnot(a[1], b[2], res[3], costing);
|
||||
ccnot(a[2], b[1], res[3], costing);
|
||||
ccnot(a[3], b[0], res[3], costing);
|
||||
ccnot(a[0], b[3], res[3], [], costing);
|
||||
ccnot(a[1], b[2], res[3], [], costing);
|
||||
ccnot(a[2], b[1], res[3], [], costing);
|
||||
ccnot(a[3], b[0], res[3], [], costing);
|
||||
|
||||
ccnot(a[0], b[2], res[2], costing);
|
||||
ccnot(a[1], b[1], res[2], costing);
|
||||
ccnot(a[2], b[0], res[2], costing);
|
||||
ccnot(a[0], b[2], res[2], [], costing);
|
||||
ccnot(a[1], b[1], res[2], [], costing);
|
||||
ccnot(a[2], b[0], res[2], [], costing);
|
||||
|
||||
ccnot(a[0], b[1], res[1], costing);
|
||||
ccnot(a[1], b[0], res[1], costing);
|
||||
ccnot(a[0], b[1], res[1], [], costing);
|
||||
ccnot(a[1], b[0], res[1], [], costing);
|
||||
|
||||
ccnot(a[0], b[0], res[0], costing);
|
||||
ccnot(a[0], b[0], res[0], [], costing);
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ namespace QGF256
|
|||
{
|
||||
body (...)
|
||||
{
|
||||
using ((c, d, e) = (Qubit[8], Qubit[8], Qubit[8]))
|
||||
use (c, d, e) = (Qubit[8], Qubit[8], Qubit[8])
|
||||
{
|
||||
Square(a, b); // A^2 --> B
|
||||
Mul(a, b, c, costing); // A*B-->C (Gives Beta_2)
|
||||
|
|
574
aes/QTests.qs
574
aes/QTests.qs
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -6,16 +6,39 @@ namespace QUtilities
|
|||
open Microsoft.Quantum.Canon;
|
||||
open Microsoft.Quantum.Diagnostics;
|
||||
|
||||
|
||||
// Blocks operations from parallelizing through this point
|
||||
// i.e., forces mutual dependencies in the call graph
|
||||
// Ruins full depth and full gate counts
|
||||
operation Block(qubits: Qubit[]) : Unit {
|
||||
body (...) {
|
||||
for i in 0..Length(qubits) - 2 {
|
||||
CNOT(qubits[i],qubits[i+1]);
|
||||
}
|
||||
for i in Length(qubits) - 1..(-1)..1 {
|
||||
CNOT(qubits[i],qubits[i-1]);
|
||||
}
|
||||
}
|
||||
controlled (controls, ... ){
|
||||
Block(controls + qubits);
|
||||
}
|
||||
controlled adjoint auto;
|
||||
}
|
||||
|
||||
operation Set (desired: Result, q1: Qubit) : Unit {
|
||||
if (desired != M(q1)) {
|
||||
X(q1);
|
||||
}
|
||||
}
|
||||
|
||||
function SWAPPEDBytes(x : Qubit[], y: Qubit[]) : (Qubit[], Qubit[]) {
|
||||
return (y, x);
|
||||
}
|
||||
|
||||
operation SWAPBytes (x: Qubit[], y: Qubit[]) : Unit {
|
||||
body (...)
|
||||
{
|
||||
for (i in 0..7)
|
||||
for i in 0..7
|
||||
{
|
||||
SWAP(x[i], y[i]);
|
||||
}
|
||||
|
@ -26,7 +49,7 @@ namespace QUtilities
|
|||
operation CNOTBytes (x: Qubit[], y: Qubit[]) : Unit {
|
||||
body (...)
|
||||
{
|
||||
for (i in 0..7)
|
||||
for i in 0..7
|
||||
{
|
||||
CNOT(x[i], y[i]);
|
||||
}
|
||||
|
@ -37,7 +60,7 @@ namespace QUtilities
|
|||
operation CNOTnBits (x: Qubit[], y: Qubit[], n: Int) : Unit {
|
||||
body (...)
|
||||
{
|
||||
for (i in 0..(n-1))
|
||||
for i in 0..(n-1)
|
||||
{
|
||||
CNOT(x[i], y[i]);
|
||||
}
|
||||
|
@ -45,13 +68,36 @@ namespace QUtilities
|
|||
adjoint auto;
|
||||
}
|
||||
|
||||
function ArraySWAP(x : Qubit[], indicesX: Int[], indicesY: Int[]) : Qubit[] {
|
||||
mutable xNew = x;
|
||||
for i in 0..Length(indicesX) - 1 {
|
||||
set xNew w/= indicesX[i] <- x[indicesY[i]];
|
||||
set xNew w/= indicesY[i] <- x[indicesX[i]];
|
||||
}
|
||||
return xNew;
|
||||
}
|
||||
|
||||
function MultiSWAP(x : Qubit[], y: Qubit[], indicesX: Int[], indicesY: Int[]) : (Qubit[], Qubit[]) {
|
||||
mutable xNew = x;
|
||||
mutable yNew = y;
|
||||
for i in 0..Length(indicesX) - 1 {
|
||||
set xNew w/= indicesX[i] <- y[indicesY[i]];
|
||||
set yNew w/= indicesY[i] <- x[indicesX[i]];
|
||||
}
|
||||
return (xNew, yNew);
|
||||
}
|
||||
|
||||
function REWIRED(x : Qubit[], index1: Int, index2: Int): Qubit[]{
|
||||
mutable newX = x;
|
||||
set newX w/= index1 <- x[index2];
|
||||
set newX w/= index2 <- x[index1];
|
||||
return newX;
|
||||
}
|
||||
|
||||
operation REWIRE (x: Qubit, y: Qubit, free: Bool) : Unit {
|
||||
body (...)
|
||||
{
|
||||
if (not free)
|
||||
{
|
||||
SWAP(x, y);
|
||||
}
|
||||
SWAP(x, y);
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
|
@ -59,20 +105,17 @@ namespace QUtilities
|
|||
operation REWIREBytes (x: Qubit[], y: Qubit[], free: Bool) : Unit {
|
||||
body (...)
|
||||
{
|
||||
if (not free)
|
||||
{
|
||||
SWAPBytes(x, y);
|
||||
}
|
||||
SWAPBytes(x, y);
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
|
||||
operation ccnot(x: Qubit, y: Qubit, z: Qubit, costing: Bool) : Unit {
|
||||
operation ccnot(x: Qubit, y: Qubit, z: Qubit, anc: Qubit[], costing: Bool) : Unit {
|
||||
body (...)
|
||||
{
|
||||
if (costing)
|
||||
{
|
||||
ccnot_T_depth_1(x, y, z);
|
||||
ccnot_T_depth_1(x, y, z, anc);
|
||||
// ccnot_7_t_depth_4(x, y, z);
|
||||
}
|
||||
else
|
||||
|
@ -108,21 +151,41 @@ namespace QUtilities
|
|||
adjoint auto;
|
||||
}
|
||||
|
||||
operation LPAND (in_1: Qubit, in_2: Qubit, outp: Qubit, costing: Bool) : Unit
|
||||
{
|
||||
body (...)
|
||||
{
|
||||
if (costing)
|
||||
{
|
||||
AND(in_1, in_2, outp);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ccnot does not assume output bit to be set to Zero!
|
||||
ccnot(in_1, in_2, outp, costing);
|
||||
|
||||
operation LPANDWithAux(control1: Qubit, control2: Qubit, target: Qubit, anc: Qubit, costing: Bool) : Unit {
|
||||
body (...) {
|
||||
if (costing){
|
||||
H(target);
|
||||
LinearPrepare(control1, control2, target, anc);
|
||||
Adjoint T(control1);
|
||||
Adjoint T(control2);
|
||||
T(target);
|
||||
T(anc);
|
||||
Adjoint LinearPrepare(control1, control2, target, anc);
|
||||
H(target);
|
||||
S(target);
|
||||
} else {
|
||||
ccnot(control1, control2, target, [anc], costing);
|
||||
}
|
||||
}
|
||||
adjoint (...) {
|
||||
if (costing) {
|
||||
H(target);
|
||||
H(control2);
|
||||
AssertMeasurementProbability([PauliZ, size=3], [control1, control2, target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10);
|
||||
|
||||
// Clumsy hack to escape the measurement-dependency bug
|
||||
if (IsResultOne(Measure([PauliZ, size=3], [control1, control2, target]))) {
|
||||
CNOT(control1, control2);
|
||||
H(control2);
|
||||
X(target);
|
||||
} else {
|
||||
H(control2);
|
||||
}
|
||||
} else {
|
||||
ccnot(control1, control2, target, [anc], costing);
|
||||
}
|
||||
}
|
||||
adjoint auto;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
@ -136,7 +199,7 @@ namespace QUtilities
|
|||
|
||||
operation AND(control1 : Qubit, control2 : Qubit, target : Qubit) : Unit {
|
||||
body (...) {
|
||||
using (anc = Qubit()) {
|
||||
use anc = Qubit() {
|
||||
H(target);
|
||||
LinearPrepare(control1, control2, target, anc);
|
||||
Adjoint T(control1);
|
||||
|
@ -150,15 +213,21 @@ namespace QUtilities
|
|||
}
|
||||
adjoint (...) {
|
||||
H(target);
|
||||
AssertProb([PauliZ], [target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10);
|
||||
if (IsResultOne(M(target))) {
|
||||
S(control1);
|
||||
S(control2);
|
||||
CNOT(control1, control2);
|
||||
Adjoint S(control2);
|
||||
H(control2);
|
||||
AssertMeasurementProbability([PauliZ], [target], One, 0.5, "Probability of the measurement must be 0.5", 1e-10);
|
||||
|
||||
// Clumsy hack to escape the measurement-dependency bug
|
||||
Block([target, control1, control2]);
|
||||
if (IsResultOne(Measure([PauliZ, size=3], [control1, control2, target]))) {
|
||||
CNOT(control1, control2);
|
||||
H(control2);
|
||||
|
||||
|
||||
X(target);
|
||||
} else {
|
||||
H(control2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,15 +279,17 @@ namespace QUtilities
|
|||
// /// # See Also
|
||||
// /// - For the circuit diagram see Figure 1 on
|
||||
// /// [ Page 3 of arXiv:1210.0974v2 ](https://arxiv.org/pdf/1210.0974v2.pdf#page=2)
|
||||
operation ccnot_T_depth_1 (control1 : Qubit, control2 : Qubit, target : Qubit) : Unit is Adj + Ctl {
|
||||
using (auxillaryRegister = Qubit[4]) {
|
||||
|
||||
operation ccnot_T_depth_1 (control1 : Qubit, control2 : Qubit, target : Qubit, anc: Qubit[]) : Unit is Adj + Ctl {
|
||||
if Length(anc) < 4 {
|
||||
use aux = Qubit[4 - Length(anc)]{
|
||||
ccnot_T_depth_1(control1, control2, target, anc+aux);
|
||||
}
|
||||
} else {
|
||||
// apply UVU† where U is outer circuit and V is inner circuit
|
||||
ApplyWithCA(TDepthOneCCNOTOuterCircuit, TDepthOneCCNOTInnerCircuit, auxillaryRegister + [target, control1, control2]);
|
||||
ApplyWithCA(TDepthOneCCNOTOuterCircuit, TDepthOneCCNOTInnerCircuit, anc + [target, control1, control2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// # See Also
|
||||
/// - Used as a part of @"Microsoft.Quantum.Samples.UnitTesting.TDepthOneCCNOT"
|
||||
/// - For the circuit diagram see Figure 1 on
|
||||
|
@ -268,12 +339,12 @@ namespace QUtilities
|
|||
/// ancilla which are not uncomputed.
|
||||
/// If controlQubits has n qubits, then this needs n-2
|
||||
/// blankControlQubits.
|
||||
operation CompressControls(controlQubits : Qubit[], blankControlQubits : Qubit[], output : Qubit, costing: Bool) : Unit {
|
||||
operation CompressControls(controlQubits : Qubit[], blankControlQubits : Qubit[], output : Qubit, andAnc: Qubit[], costing: Bool) : Unit {
|
||||
body (...){
|
||||
let nControls = Length(controlQubits);
|
||||
let nNewControls = Length(blankControlQubits);
|
||||
if (nControls == 2){
|
||||
LPAND(controlQubits[0], controlQubits[1], output, costing);
|
||||
LPANDWithAux(controlQubits[0], controlQubits[1], output, andAnc[0], costing);
|
||||
} else {
|
||||
Fact(nNewControls >= nControls/2, $"Cannot compress {nControls}
|
||||
control qubits to {nNewControls} qubits without more ancilla");
|
||||
|
@ -281,13 +352,13 @@ namespace QUtilities
|
|||
$"Cannot compress {nControls} control qubits into
|
||||
{nNewControls} qubits because there are too few controls");
|
||||
let compressLength = nControls - nNewControls;
|
||||
for (idx in 0.. 2 .. nControls - 2){
|
||||
LPAND(controlQubits[idx], controlQubits[idx + 1], blankControlQubits[idx/2], costing);
|
||||
for idx in 0.. 2 .. nControls - 2{
|
||||
LPANDWithAux(controlQubits[idx], controlQubits[idx + 1], blankControlQubits[idx/2], andAnc[idx/2], costing);
|
||||
}
|
||||
if (nControls % 2 == 0){
|
||||
CompressControls(blankControlQubits[0.. nControls/2 - 1], blankControlQubits[nControls/2 .. nNewControls - 1], output, costing);
|
||||
CompressControls(blankControlQubits[0.. nControls/2 - 1], blankControlQubits[nControls/2 .. nNewControls - 1], output, andAnc[(nControls)/2..Length(andAnc)-1], costing);
|
||||
} else {
|
||||
CompressControls([controlQubits[nControls - 1]] + blankControlQubits[0.. nControls/2 - 1], blankControlQubits[nControls/2 .. nNewControls - 1], output, costing);
|
||||
CompressControls([controlQubits[nControls - 1]] + blankControlQubits[0.. nControls/2 - 1], blankControlQubits[nControls/2 .. nNewControls - 1], output, andAnc[(nControls-1)/2..Length(andAnc)-1], costing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,13 +384,13 @@ namespace QUtilities
|
|||
let nQubits = Length(xs);
|
||||
if (nQubits == 1){
|
||||
CNOT(xs[0], output);
|
||||
} elif (nQubits == 2){
|
||||
ccnot(xs[0], xs[1], output, costing);
|
||||
// } elif (nQubits == 2){
|
||||
// ccnot(xs[0], xs[1], output, costing);
|
||||
} else {
|
||||
using ((spareControls, ancillaOutput) = (Qubit[nQubits - 2], Qubit())){
|
||||
CompressControls(xs, spareControls, ancillaOutput, costing);
|
||||
use (spareControls, ancillaOutput, andAnc) = (Qubit[nQubits - 2], Qubit(), Qubit[nQubits-1]){
|
||||
CompressControls(xs, spareControls, ancillaOutput, andAnc, costing);
|
||||
CNOT(ancillaOutput, output);
|
||||
(Adjoint CompressControls)(xs, spareControls, ancillaOutput, costing);
|
||||
(Adjoint CompressControls)(xs, spareControls, ancillaOutput, andAnc, costing);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -337,7 +408,7 @@ namespace QUtilities
|
|||
if (Length(target) == Length(qubitstring))
|
||||
{
|
||||
// flip wires expected to be 0 in the target, to allow comparison
|
||||
for (i in 0..(Length(target)-1))
|
||||
for i in 0..(Length(target)-1)
|
||||
{
|
||||
if (target[i] == false)
|
||||
{
|
||||
|
@ -349,7 +420,7 @@ namespace QUtilities
|
|||
TestIfAllOnes(qubitstring, success, costing);
|
||||
|
||||
// undo flipping
|
||||
for (i in 0..(Length(target)-1))
|
||||
for i in 0..(Length(target)-1)
|
||||
{
|
||||
if (target[i] == false)
|
||||
{
|
||||
|
@ -358,7 +429,7 @@ namespace QUtilities
|
|||
}
|
||||
}
|
||||
|
||||
// this can also be done in the following way using the Q# standard library
|
||||
// this can also be done in the following way use the Q# standard library
|
||||
// but it's more expensive
|
||||
// let controlled_op = ControlledOnBitString(target, X);
|
||||
// controlled_op(qubitstring, success);
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import qsharp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%qsharp\n",
|
||||
"\n",
|
||||
"operation SayHello(name : String) : Unit {\n",
|
||||
" Message($\"Hello, {name}!\");\n",
|
||||
"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Hello, quantum world!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"SayHello.simulate(name=\"quantum world\");"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
|
@ -0,0 +1,308 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import qsharp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\n",
|
||||
"\n",
|
||||
"%%qsharp\n",
|
||||
"\n",
|
||||
"operation SayHello(name : String) : Unit {\n",
|
||||
" Message($\"Hello, {name}!\");\n",
|
||||
"}\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"No such magic command %simulate_sparse.\n",
|
||||
"Possibly similar magic commands:\n",
|
||||
"- %simulate\n",
|
||||
"- %azure.status\n",
|
||||
"- %estimate\n",
|
||||
"To get a list of all available magic commands, run %lsmagic, or visit https://docs.microsoft.com/qsharp/api/iqsharp-magic/.\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"SayHello.simulate_sparse(name = \"quantum world\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/json": {
|
||||
"cell": {
|
||||
"!": "OSMagics",
|
||||
"HTML": "Other",
|
||||
"SVG": "Other",
|
||||
"bash": "Other",
|
||||
"capture": "ExecutionMagics",
|
||||
"debug": "ExecutionMagics",
|
||||
"file": "Other",
|
||||
"html": "DisplayMagics",
|
||||
"javascript": "DisplayMagics",
|
||||
"js": "DisplayMagics",
|
||||
"latex": "DisplayMagics",
|
||||
"markdown": "DisplayMagics",
|
||||
"perl": "Other",
|
||||
"prun": "ExecutionMagics",
|
||||
"pypy": "Other",
|
||||
"python": "Other",
|
||||
"python2": "Other",
|
||||
"python3": "Other",
|
||||
"qsharp": "Other",
|
||||
"ruby": "Other",
|
||||
"script": "ScriptMagics",
|
||||
"sh": "Other",
|
||||
"svg": "DisplayMagics",
|
||||
"sx": "OSMagics",
|
||||
"system": "OSMagics",
|
||||
"time": "ExecutionMagics",
|
||||
"timeit": "ExecutionMagics",
|
||||
"writefile": "OSMagics"
|
||||
},
|
||||
"line": {
|
||||
"alias": "OSMagics",
|
||||
"alias_magic": "BasicMagics",
|
||||
"autoawait": "AsyncMagics",
|
||||
"autocall": "AutoMagics",
|
||||
"automagic": "AutoMagics",
|
||||
"autosave": "KernelMagics",
|
||||
"bookmark": "OSMagics",
|
||||
"cat": "Other",
|
||||
"cd": "OSMagics",
|
||||
"clear": "KernelMagics",
|
||||
"colors": "BasicMagics",
|
||||
"conda": "PackagingMagics",
|
||||
"config": "ConfigMagics",
|
||||
"connect_info": "KernelMagics",
|
||||
"cp": "Other",
|
||||
"debug": "ExecutionMagics",
|
||||
"dhist": "OSMagics",
|
||||
"dirs": "OSMagics",
|
||||
"doctest_mode": "BasicMagics",
|
||||
"ed": "Other",
|
||||
"edit": "KernelMagics",
|
||||
"env": "OSMagics",
|
||||
"gui": "BasicMagics",
|
||||
"hist": "Other",
|
||||
"history": "HistoryMagics",
|
||||
"killbgscripts": "ScriptMagics",
|
||||
"ldir": "Other",
|
||||
"less": "KernelMagics",
|
||||
"lf": "Other",
|
||||
"lk": "Other",
|
||||
"ll": "Other",
|
||||
"load": "CodeMagics",
|
||||
"load_ext": "ExtensionMagics",
|
||||
"loadpy": "CodeMagics",
|
||||
"logoff": "LoggingMagics",
|
||||
"logon": "LoggingMagics",
|
||||
"logstart": "LoggingMagics",
|
||||
"logstate": "LoggingMagics",
|
||||
"logstop": "LoggingMagics",
|
||||
"ls": "Other",
|
||||
"lsmagic": "BasicMagics",
|
||||
"lx": "Other",
|
||||
"macro": "ExecutionMagics",
|
||||
"magic": "BasicMagics",
|
||||
"man": "KernelMagics",
|
||||
"matplotlib": "PylabMagics",
|
||||
"mkdir": "Other",
|
||||
"more": "KernelMagics",
|
||||
"mv": "Other",
|
||||
"notebook": "BasicMagics",
|
||||
"page": "BasicMagics",
|
||||
"pastebin": "CodeMagics",
|
||||
"pdb": "ExecutionMagics",
|
||||
"pdef": "NamespaceMagics",
|
||||
"pdoc": "NamespaceMagics",
|
||||
"pfile": "NamespaceMagics",
|
||||
"pinfo": "NamespaceMagics",
|
||||
"pinfo2": "NamespaceMagics",
|
||||
"pip": "PackagingMagics",
|
||||
"popd": "OSMagics",
|
||||
"pprint": "BasicMagics",
|
||||
"precision": "BasicMagics",
|
||||
"prun": "ExecutionMagics",
|
||||
"psearch": "NamespaceMagics",
|
||||
"psource": "NamespaceMagics",
|
||||
"pushd": "OSMagics",
|
||||
"pwd": "OSMagics",
|
||||
"pycat": "OSMagics",
|
||||
"pylab": "PylabMagics",
|
||||
"qtconsole": "KernelMagics",
|
||||
"quickref": "BasicMagics",
|
||||
"recall": "HistoryMagics",
|
||||
"rehashx": "OSMagics",
|
||||
"reload_ext": "ExtensionMagics",
|
||||
"rep": "Other",
|
||||
"rerun": "HistoryMagics",
|
||||
"reset": "NamespaceMagics",
|
||||
"reset_selective": "NamespaceMagics",
|
||||
"rm": "Other",
|
||||
"rmdir": "Other",
|
||||
"run": "ExecutionMagics",
|
||||
"save": "CodeMagics",
|
||||
"sc": "OSMagics",
|
||||
"set_env": "OSMagics",
|
||||
"store": "StoreMagics",
|
||||
"sx": "OSMagics",
|
||||
"system": "OSMagics",
|
||||
"tb": "ExecutionMagics",
|
||||
"time": "ExecutionMagics",
|
||||
"timeit": "ExecutionMagics",
|
||||
"unalias": "OSMagics",
|
||||
"unload_ext": "ExtensionMagics",
|
||||
"who": "NamespaceMagics",
|
||||
"who_ls": "NamespaceMagics",
|
||||
"whos": "NamespaceMagics",
|
||||
"xdel": "NamespaceMagics",
|
||||
"xmode": "BasicMagics"
|
||||
}
|
||||
},
|
||||
"text/plain": [
|
||||
"Available line magics:\n",
|
||||
"%alias %alias_magic %autoawait %autocall %automagic %autosave %bookmark %cat %cd %clear %colors %conda %config %connect_info %cp %debug %dhist %dirs %doctest_mode %ed %edit %env %gui %hist %history %killbgscripts %ldir %less %lf %lk %ll %load %load_ext %loadpy %logoff %logon %logstart %logstate %logstop %ls %lsmagic %lx %macro %magic %man %matplotlib %mkdir %more %mv %notebook %page %pastebin %pdb %pdef %pdoc %pfile %pinfo %pinfo2 %pip %popd %pprint %precision %prun %psearch %psource %pushd %pwd %pycat %pylab %qtconsole %quickref %recall %rehashx %reload_ext %rep %rerun %reset %reset_selective %rm %rmdir %run %save %sc %set_env %store %sx %system %tb %time %timeit %unalias %unload_ext %who %who_ls %whos %xdel %xmode\n",
|
||||
"\n",
|
||||
"Available cell magics:\n",
|
||||
"%%! %%HTML %%SVG %%bash %%capture %%debug %%file %%html %%javascript %%js %%latex %%markdown %%perl %%prun %%pypy %%python %%python2 %%python3 %%qsharp %%ruby %%script %%sh %%svg %%sx %%system %%time %%timeit %%writefile\n",
|
||||
"\n",
|
||||
"Automagic is ON, % prefix IS NOT needed for line magics."
|
||||
]
|
||||
},
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%lsmagic"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "'QSharpCallable' object has no attribute 'simulate_dense'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m<ipython-input-5-58385154ab68>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mSayHello\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulate_dense\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m\"quantum world\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m: 'QSharpCallable' object has no attribute 'simulate_dense'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"SayHello.simulate_dense(name = \"quantum world\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%%qsharp\n",
|
||||
"\n",
|
||||
"operation nop(): Unit {}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "AttributeError",
|
||||
"evalue": "'QSharpCallable' object has no attribute 'simulate_dense'",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m<ipython-input-10-c9837ab1e587>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mnop\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mnop\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulate_dense\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[0;31mAttributeError\u001b[0m: 'QSharpCallable' object has no attribute 'simulate_dense'"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"nop.simulate()\n",
|
||||
"nop.simulate_dense()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "SyntaxError",
|
||||
"evalue": "invalid syntax (<ipython-input-11-eb0b1725da69>, line 1)",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-11-eb0b1725da69>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m qsharp version\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"qsharp version"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
|
@ -8,15 +8,15 @@ using Microsoft.Quantum.Simulation.Simulators;
|
|||
|
||||
static class Utilities
|
||||
{
|
||||
public static int[] Bits(int x)
|
||||
public static Result[] Bits(int x)
|
||||
{
|
||||
Trace.Assert(x < 256);
|
||||
Trace.Assert(x >= 0);
|
||||
int[] bits = new int[8];
|
||||
Result[] bits = new Result[8];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
bits[i] = (x & (1 << i)) > 0 ? 1 : 0;
|
||||
bits[i] = (x & (1 << i)) > 0 ? Result.One : Result.Zero;
|
||||
}
|
||||
|
||||
return bits;
|
||||
|
@ -41,14 +41,23 @@ static class Utilities
|
|||
|
||||
public static QArray<Result> nQBits(int n, bool val)
|
||||
{
|
||||
int[] bits = new int[n];
|
||||
Result[] bits = new Result[n];
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
bits[i] = val ? 1 : 0;
|
||||
bits[i] = val ? Microsoft.Quantum.Simulation.Core.Result.One : Microsoft.Quantum.Simulation.Core.Result.Zero;
|
||||
}
|
||||
return new QArray<Result>(bits);
|
||||
}
|
||||
|
||||
public static QArray<Result> BitsToQubits(bool[] vals)
|
||||
{
|
||||
Result[] qubits = new Result[vals.Length];
|
||||
for (int i =0; i < vals.Length; i++){
|
||||
qubits[i] = vals[i] ? Microsoft.Quantum.Simulation.Core.Result.One : Microsoft.Quantum.Simulation.Core.Result.Zero;
|
||||
}
|
||||
return new QArray<Result>(qubits);
|
||||
}
|
||||
|
||||
public static void PrintBits(bool[] bits)
|
||||
{
|
||||
for (int i = 8; i > 0; i--)
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Library that deals with making human-friendly the CSV tracer's output
|
||||
namespace cswrapper
|
||||
{
|
||||
using FileHelpers; // csv parsing
|
||||
|
||||
[DelimitedRecord("\t")]
|
||||
[IgnoreFirst(1)]
|
||||
public class WidthCounterCSV
|
||||
{
|
||||
public string Name
|
||||
{ get; set; }
|
||||
|
||||
public string Variant
|
||||
{ get; set; }
|
||||
|
||||
public string Caller
|
||||
{ get; set; }
|
||||
|
||||
public string CallerVariant
|
||||
{ get; set; }
|
||||
|
||||
public long Count
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal InputWidthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long InputWidthSum
|
||||
{ get; set; }
|
||||
|
||||
public long InputWidthMin
|
||||
{ get; set; }
|
||||
|
||||
public long InputWidthMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ExtraWidthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long ExtraWidthSum
|
||||
{ get; set; }
|
||||
|
||||
public long ExtraWidthMin
|
||||
{ get; set; }
|
||||
|
||||
public long ExtraWidthMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal ReturnWidthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long ReturnWidthSum
|
||||
{ get; set; }
|
||||
|
||||
public long ReturnWidthMin
|
||||
{ get; set; }
|
||||
|
||||
public long ReturnWidthMax
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthAverage
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthSecondMoment
|
||||
{ get; set; }
|
||||
|
||||
[FieldConverter(typeof(QDecimalConverter))]
|
||||
public decimal BorrowedWidthVariance
|
||||
{ get; set; }
|
||||
|
||||
public long BorrowedWidthSum
|
||||
{ get; set; }
|
||||
|
||||
public long BorrowedWidthMin
|
||||
{ get; set; }
|
||||
|
||||
public long BorrowedWidthMax
|
||||
{ get; set; }
|
||||
}
|
||||
}
|
|
@ -1,17 +1,16 @@
|
|||
<!-- Copyright (c) Microsoft Corporation.
|
||||
Licensed under the MIT license. -->
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.Quantum.Sdk/0.27.244707"><!--Microsoft.NET.Sdk"24.210930>-->
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FileHelpers" Version="3.4.0" />
|
||||
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.7.1905.3109" />
|
||||
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.7.1905.3109" />
|
||||
<PackageReference Include="FileHelpers" Version="3.4.1" />
|
||||
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.27.244707" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -512,7 +512,7 @@ class Tests:
|
|||
assert(res == [True] * trials)
|
||||
|
||||
@staticmethod
|
||||
def GroverOracle(smart_wide=True, Nr=10, Nk=4, pairs=1, in_place_mixcolumn=False, cost=False):
|
||||
def GroverOracle(smart_wide=True, Nr=10, Nk=4, pairs=1, in_place_mixcolumn=True, widest = False, cost=False):
|
||||
"""
|
||||
TEST:
|
||||
>>> Tests.GroverOracle(smart_wide=True, in_place_mixcolumn=False, Nr=10, Nk=4, pairs=1)
|
||||
|
@ -540,6 +540,7 @@ class Tests:
|
|||
>>> Tests.GroverOracle(smart_wide=True, in_place_mixcolumn=True, Nr=14, Nk=8, pairs=2)
|
||||
Testing GroverOracle(smart_wide=True, in_place_mixcolumn=True, Nr=14, Nk=8, pairs=2)
|
||||
|
||||
|
||||
# >>> Tests.GroverOracle(smart_wide=True, in_place_mixcolumn=False, Nr=14, Nk=8, pairs=3)
|
||||
# Testing GroverOracle(smart_wide=True, in_place_mixcolumn=False, Nr=14, Nk=8, pairs=3)
|
||||
# >>> Tests.GroverOracle(smart_wide=True, in_place_mixcolumn=True, Nr=14, Nk=8, pairs=3)
|
||||
|
@ -580,7 +581,7 @@ class Tests:
|
|||
if flip:
|
||||
qkey[0] = 0 if qkey[0] == 1 else 1
|
||||
|
||||
qgrover = GroverOracle.toffoli_simulate(_key=qkey, _plaintexts=qmessage, target_ciphertext=target_ciphertext, pairs=pairs, Nr=Nr, Nk=Nk, in_place_mixcolumn=in_place_mixcolumn, costing=False)
|
||||
qgrover = GroverOracle.toffoli_simulate(_key=qkey, _plaintexts=qmessage, target_ciphertext=target_ciphertext, pairs=pairs, Nr=Nr, Nk=Nk, in_place_mixcolumn=in_place_mixcolumn, widest = widest, costing=False)
|
||||
res.append(qgrover == int(not flip))
|
||||
assert(res == [True] * trials)
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
// // Functions to run an operation several times and write timing data to a file or console
|
||||
|
||||
// using System;
|
||||
// using System.Collections.Generic;
|
||||
// using System.Runtime.InteropServices;
|
||||
// using System.Text;
|
||||
// using Microsoft.Quantum.Simulation.Simulators;
|
||||
// using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators;
|
||||
// using Microsoft.Quantum.Simulation.Core;
|
||||
// using Microsoft.Quantum.Canon;
|
||||
// using Microsoft.Quantum.Simulation.Simulators.QCTraceSimulators.Implementation;
|
||||
|
||||
// namespace Microsoft.Quantum.Canon
|
||||
// {
|
||||
// public partial class Touch
|
||||
// {
|
||||
// private QCTraceSimulator simulator;
|
||||
// public class Native : Touch
|
||||
// {
|
||||
// public Native(IOperationFactory m) : base(m)
|
||||
// {
|
||||
// simulator = m as QCTraceSimulator;
|
||||
// }
|
||||
// public override Func<IQArray<Qubit>, QVoid> __Body__ => (__in__) =>
|
||||
// {
|
||||
|
||||
// // (__T__ location, ICallable op, __U__ input, Int64 num_tests) = __in__;
|
||||
// // var filename = (location is QVoid) ? "" : location.ToString();
|
||||
// if (simulator != null)
|
||||
// {
|
||||
// (QCTraceSimulatorImpl)simulator.DoPrimitiveOperation((int)PrimitiveOperationsGroups.R, __in__,
|
||||
// 0, true);
|
||||
|
||||
|
||||
// // ((SparseSimulatorProcessor)simulator.QuantumProcessor).BenchmarkInit(filename, op.FullName);
|
||||
// // for (Int64 i = 0; i < num_tests; i++)
|
||||
// // {
|
||||
// // ((SparseSimulatorProcessor)simulator.QuantumProcessor).StartOp(op.FullName);
|
||||
// // op.Apply<__V__>(input);
|
||||
// // ((SparseSimulatorProcessor)simulator.QuantumProcessor).EndOp();
|
||||
// // }
|
||||
// // ((SparseSimulatorProcessor)simulator.QuantumProcessor).BenchmarkFinalize();
|
||||
// return QVoid.Instance;
|
||||
// }
|
||||
// else
|
||||
// { // If it's another type of simulator: do nothing
|
||||
|
||||
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
namespace Microsoft.Quantum.Canon {
|
||||
|
||||
open Microsoft.Quantum.Intrinsic;
|
||||
|
||||
|
||||
operation Touch (qubits: Qubit[]) : Unit {
|
||||
body intrinsic;
|
||||
}
|
||||
}
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FileHelpers" Version="3.4.0" />
|
||||
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.7.1905.3109" />
|
||||
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.7.1905.3109" />
|
||||
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.24.208024" />
|
||||
<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.24.208024" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче