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

Commit 78e152b

Browse files
NoOp Reference Change (#494)
Added NoOp to precondition verification for ClassicallyControlled.
1 parent deca80d commit 78e152b

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

src/QsCompiler/Compiler/RewriteSteps/ClassicallyControlled.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the MIT License.
33

44
using System.Collections.Generic;
5+
using System.Collections.Immutable;
56
using System.Linq;
7+
using Microsoft.Quantum.QsCompiler.DataTypes;
68
using Microsoft.Quantum.QsCompiler.SyntaxTree;
79
using Microsoft.Quantum.QsCompiler.Transformations.ClassicallyControlled;
810

@@ -30,20 +32,7 @@ public ClassicallyControlled()
3032

3133
public bool PreconditionVerification(QsCompilation compilation)
3234
{
33-
var controlNs = compilation.Namespaces
34-
.FirstOrDefault(ns => ns.Name.Equals(BuiltIn.ClassicallyControlledNamespace));
35-
36-
if (controlNs == null)
37-
{
38-
return false;
39-
}
40-
41-
var providedOperations = new QsNamespace[] { controlNs }
42-
.Callables()
43-
.Select(c => c.FullName)
44-
.ToHashSet();
45-
var requiredBuiltIns = new HashSet<QsQualifiedName>()
46-
{
35+
var classicallyControlledRequired = ImmutableHashSet.Create(
4736
BuiltIn.ApplyIfZero.FullName,
4837
BuiltIn.ApplyIfZeroA.FullName,
4938
BuiltIn.ApplyIfZeroC.FullName,
@@ -58,9 +47,23 @@ public bool PreconditionVerification(QsCompilation compilation)
5847
BuiltIn.ApplyIfElseRA.FullName,
5948
BuiltIn.ApplyIfElseRC.FullName,
6049
BuiltIn.ApplyIfElseRCA.FullName
61-
};
50+
);
6251

63-
return requiredBuiltIns.IsSubsetOf(providedOperations);
52+
if (!CheckForRequired(compilation, BuiltIn.ClassicallyControlledNamespace, classicallyControlledRequired))
53+
{
54+
return false;
55+
}
56+
57+
var cannonRequired = ImmutableHashSet.Create(
58+
BuiltIn.NoOp.FullName
59+
);
60+
61+
if (!CheckForRequired(compilation, BuiltIn.CanonNamespace, cannonRequired))
62+
{
63+
return false;
64+
}
65+
66+
return true;
6467
}
6568

6669
public bool Transformation(QsCompilation compilation, out QsCompilation transformed)
@@ -73,5 +76,23 @@ public bool PostconditionVerification(QsCompilation compilation)
7376
{
7477
throw new System.NotImplementedException();
7578
}
79+
80+
private bool CheckForRequired(QsCompilation compilation, NonNullable<string> namespaceName, ImmutableHashSet<QsQualifiedName> requiredBuiltIns)
81+
{
82+
var builtInNs = compilation.Namespaces
83+
.FirstOrDefault(ns => ns.Name.Equals(namespaceName));
84+
85+
if (builtInNs == null)
86+
{
87+
return false;
88+
}
89+
90+
var providedOperations = new QsNamespace[] { builtInNs }
91+
.Callables()
92+
.Select(c => c.FullName)
93+
.ToImmutableHashSet();
94+
95+
return requiredBuiltIns.IsSubsetOf(providedOperations);
96+
}
7697
}
7798
}

0 commit comments

Comments
 (0)