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

Conversation

@bettinaheim
Copy link
Contributor

The warning for reserved underscore patterns is now an error.
The error for entry points in libraries is now a warning (addressing #571).

Copy link
Contributor

@rmshaffer rmshaffer left a comment

Choose a reason for hiding this comment

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

Note that this should also resolve microsoft/iqsharp#266 without any additional changes in IQ#. I will test that after this is merged.

@rmshaffer
Copy link
Contributor

I've looked into the CI failure here a little bit, specifically, the error in the IQ# test called TestRuntimeCapabilities.

In this test, we attempt to compile this Q# source file as a library. Specifically, the CompilationLoader object is created using IsExecutable = false, AssemblyConstants = { ["ProcessorArchitecture"] = "honeywell.mock" }, and RuntimeCapabilities = QPRGen1.

The compilation produces the new EntryPointInLibrary warning, as expected, but then the resulting built DLL does not appear to have any Q# operations in it. Specifically, our call to ProjectManager.LoadReferencedAssemblies() returns an empty dictionary:
https://github.com/microsoft/iqsharp/blob/249490833c5d4c0728c911eab796b7b22394ffd6/src/Core/AssemblyInfo.cs#L73

Is there something about changing the EntryPointInLibrary error to a warning here that would cause the resulting assembly to be different?

For reference, the generated C# code from the above Q# compilation is pasted below. Does this look as expected?

//------------------------------------------------------------------------------
// <auto-generated>                                                             
//     This code was generated by a tool.                                       
//     Changes to this file may cause incorrect behavior and will be lost if    
//     the code is regenerated.                                                 
// </auto-generated>                                                            
//------------------------------------------------------------------------------
#pragma warning disable 436
#pragma warning disable 162
#pragma warning disable 1591
using System;
using Microsoft.Quantum.Core;
using Microsoft.Quantum.Intrinsic;
using Microsoft.Quantum.Simulation.Core;

[assembly: CallableDeclaration("{\"Kind\":{\"Case\":\"Operation\"},\"QualifiedName\":{\"Namespace\":\"Tests.qss\",\"Name\":\"CompareMeasurementResult\"},\"Attributes\":[{\"TypeId\":{\"Case\":\"Null\"},\"Argument\":{\"Item1\":{\"Case\":\"UnitValue\"},\"Item2\":[],\"Item3\":{\"Case\":\"UnitType\"},\"Item4\":{\"IsMutable\":false,\"HasLocalQuantumDependency\":false},\"Item5\":{\"Case\":\"Value\",\"Fields\":[{\"Item1\":{\"Line\":1,\"Column\":12},\"Item2\":{\"Line\":1,\"Column\":14}}]}},\"Offset\":{\"Item1\":7,\"Item2\":4},\"Comments\":{\"OpeningComments\":[],\"ClosingComments\":[]}}],\"Modifiers\":{\"Access\":{\"Case\":\"DefaultAccess\"}},\"SourceFile\":\"C:\\\\QDK\\\\iqsharp\\\\src\\\\Tests\\\\bin\\\\Debug\\\\netcoreapp3.1\\\\Workspace.QPRGen1\\\\Operations.qs\",\"Position\":{\"Item1\":8,\"Item2\":4},\"SymbolRange\":{\"Item1\":{\"Line\":1,\"Column\":11},\"Item2\":{\"Line\":1,\"Column\":35}},\"ArgumentTuple\":{\"Case\":\"QsTuple\",\"Fields\":[[]]},\"Signature\":{\"TypeParameters\":[],\"ArgumentType\":{\"Case\":\"UnitType\"},\"ReturnType\":{\"Case\":\"Result\"},\"Information\":{\"Characteristics\":{\"Case\":\"EmptySet\"},\"InferredInformation\":{\"IsSelfAdjoint\":false,\"IsIntrinsic\":false}}},\"Documentation\":[]}")]
[assembly: SpecializationDeclaration("{\"Kind\":{\"Case\":\"QsBody\"},\"TypeArguments\":{\"Case\":\"Null\"},\"Information\":{\"Characteristics\":{\"Case\":\"EmptySet\"},\"InferredInformation\":{\"IsSelfAdjoint\":false,\"IsIntrinsic\":false}},\"Parent\":{\"Namespace\":\"Tests.qss\",\"Name\":\"CompareMeasurementResult\"},\"Attributes\":[],\"SourceFile\":\"C:\\\\QDK\\\\iqsharp\\\\src\\\\Tests\\\\bin\\\\Debug\\\\netcoreapp3.1\\\\Workspace.QPRGen1\\\\Operations.qs\",\"Position\":{\"Item1\":8,\"Item2\":4},\"HeaderRange\":{\"Item1\":{\"Line\":1,\"Column\":11},\"Item2\":{\"Line\":1,\"Column\":35}},\"Documentation\":[]}")]
[assembly: CallableDeclaration("{\"Kind\":{\"Case\":\"Operation\"},\"QualifiedName\":{\"Namespace\":\"Tests.qss\",\"Name\":\"_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult\"},\"Attributes\":[],\"Modifiers\":{\"Access\":{\"Case\":\"Internal\"}},\"SourceFile\":\"C:\\\\QDK\\\\iqsharp\\\\src\\\\Tests\\\\bin\\\\Debug\\\\netcoreapp3.1\\\\Workspace.QPRGen1\\\\Operations.qs\",\"Position\":\"Undefined\",\"SymbolRange\":\"Undefined\",\"ArgumentTuple\":{\"Case\":\"QsTuple\",\"Fields\":[[{\"Case\":\"QsTupleItem\",\"Fields\":[{\"VariableName\":{\"Case\":\"ValidName\",\"Fields\":[\"r\"]},\"Type\":{\"Case\":\"Result\"},\"InferredInformation\":{\"IsMutable\":false,\"HasLocalQuantumDependency\":false},\"Position\":{\"Case\":\"Value\",\"Fields\":[{\"Item1\":2,\"Item2\":12}]},\"Range\":{\"Item1\":{\"Line\":1,\"Column\":5},\"Item2\":{\"Line\":1,\"Column\":6}}}]},{\"Case\":\"QsTupleItem\",\"Fields\":[{\"VariableName\":{\"Case\":\"ValidName\",\"Fields\":[\"q\"]},\"Type\":{\"Case\":\"Qubit\"},\"InferredInformation\":{\"IsMutable\":false,\"HasLocalQuantumDependency\":false},\"Position\":{\"Case\":\"Value\",\"Fields\":[{\"Item1\":1,\"Item2\":8}]},\"Range\":{\"Item1\":{\"Line\":1,\"Column\":8},\"Item2\":{\"Line\":1,\"Column\":9}}}]}]]},\"Signature\":{\"TypeParameters\":[],\"ArgumentType\":{\"Case\":\"TupleType\",\"Fields\":[[{\"Case\":\"Result\"},{\"Case\":\"Qubit\"}]]},\"ReturnType\":{\"Case\":\"UnitType\"},\"Information\":{\"Characteristics\":{\"Case\":\"EmptySet\"},\"InferredInformation\":{\"IsSelfAdjoint\":false,\"IsIntrinsic\":false}}},\"Documentation\":[]}")]
[assembly: SpecializationDeclaration("{\"Kind\":{\"Case\":\"QsBody\"},\"TypeArguments\":{\"Case\":\"Null\"},\"Information\":{\"Characteristics\":{\"Case\":\"EmptySet\"},\"InferredInformation\":{\"IsSelfAdjoint\":false,\"IsIntrinsic\":false}},\"Parent\":{\"Namespace\":\"Tests.qss\",\"Name\":\"_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult\"},\"Attributes\":[],\"SourceFile\":\"C:\\\\QDK\\\\iqsharp\\\\src\\\\Tests\\\\bin\\\\Debug\\\\netcoreapp3.1\\\\Workspace.QPRGen1\\\\Operations.qs\",\"Position\":\"Undefined\",\"HeaderRange\":\"Undefined\",\"Documentation\":[]}")]
#line hidden
namespace Tests.qss
{
    [SourceLocation("C:\\QDK\\iqsharp\\src\\Tests\\bin\\Debug\\netcoreapp3.1\\Workspace.QPRGen1\\Operations.qs", OperationFunctor.Body, 9, -1)]
    public partial class CompareMeasurementResult : Operation<QVoid, Result>, ICallable
    {
        public CompareMeasurementResult(IOperationFactory m) : base(m)
        {
        }

        String ICallable.Name => "CompareMeasurementResult";
        String ICallable.FullName => "Tests.qss.CompareMeasurementResult";
        protected Allocate Allocate__
        {
            get;
            set;
        }

        protected Release Release__
        {
            get;
            set;
        }

        protected ICallable<Qubit, Result> M__
        {
            get;
            set;
        }

        protected ICallable Microsoft__Quantum__Simulation__QuantumProcessor__Extensions__ApplyIfOne
        {
            get;
            set;
        }

        private protected ICallable<(Result,Qubit), QVoid> _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult__
        {
            get;
            set;
        }

        public override Func<QVoid, Result> __Body__ => (__in__) =>
        {
#line hidden
            {
#line 10 "C:\\QDK\\iqsharp\\src\\Tests\\bin\\Debug\\netcoreapp3.1\\Workspace.QPRGen1\\Operations.qs"
                var q = Allocate__.Apply();
#line hidden
                bool __arg1__ = true;
                try
                {
#line 11 "C:\\QDK\\iqsharp\\src\\Tests\\bin\\Debug\\netcoreapp3.1\\Workspace.QPRGen1\\Operations.qs"
                    var r = M__.Apply(q);
#line 9 "C:\\QDK\\iqsharp\\src\\Tests\\bin\\Debug\\netcoreapp3.1\\Workspace.QPRGen1\\Operations.qs"
                    Microsoft__Quantum__Simulation__QuantumProcessor__Extensions__ApplyIfOne.Apply((r, (_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult__, (r, q))));
#line 16 "C:\\QDK\\iqsharp\\src\\Tests\\bin\\Debug\\netcoreapp3.1\\Workspace.QPRGen1\\Operations.qs"
                    return r;
                }
#line hidden
                catch
                {
                    __arg1__ = false;
                    throw;
                }
#line hidden
                finally
                {
                    if (__arg1__)
                    {
#line hidden
                        Release__.Apply(q);
                    }
                }
            }
        }

        ;
        public override void __Init__()
        {
            this.Allocate__ = this.__Factory__.Get<Allocate>(typeof(global::Microsoft.Quantum.Intrinsic.Allocate));
            this.Release__ = this.__Factory__.Get<Release>(typeof(global::Microsoft.Quantum.Intrinsic.Release));
            this.M__ = this.__Factory__.Get<ICallable<Qubit, Result>>(typeof(global::Microsoft.Quantum.Intrinsic.M));
            this.Microsoft__Quantum__Simulation__QuantumProcessor__Extensions__ApplyIfOne = this.__Factory__.Get<ICallable>(typeof(global::Microsoft.Quantum.Simulation.QuantumProcessor.Extensions.ApplyIfOne<>));
            this._001342c68c374a11b857653cfc34cd36_CompareMeasurementResult__ = this.__Factory__.Get<ICallable<(Result,Qubit), QVoid>>(typeof(_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult));
        }

        public override IApplyData __DataIn__(QVoid data) => data;
        public override IApplyData __DataOut__(Result data) => new QTuple<Result>(data);
        public static System.Threading.Tasks.Task<Result> Run(IOperationFactory __m__)
        {
            return __m__.Run<CompareMeasurementResult, QVoid, Result>(QVoid.Instance);
        }
    }

    internal partial class _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult : Operation<(Result,Qubit), QVoid>, ICallable
    {
        public _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult(IOperationFactory m) : base(m)
        {
        }

        public class In : QTuple<(Result,Qubit)>, IApplyData
        {
            public In((Result,Qubit) data) : base(data)
            {
            }

            System.Collections.Generic.IEnumerable<Qubit> IApplyData.Qubits
            {
                get
                {
                    yield return Data.Item2;
                }
            }
        }

        String ICallable.Name => "_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult";
        String ICallable.FullName => "Tests.qss._001342c68c374a11b857653cfc34cd36_CompareMeasurementResult";
        protected IUnitary<Qubit> H__
        {
            get;
            set;
        }

        protected ICallable<Qubit, QVoid> Reset__
        {
            get;
            set;
        }

        public override Func<(Result,Qubit), QVoid> __Body__ => (__in__) =>
        {
            var (r,q) = __in__;
            H__.Apply(q);
            Reset__.Apply(q);
#line hidden
            return QVoid.Instance;
        }

        ;
        public override void __Init__()
        {
            this.H__ = this.__Factory__.Get<IUnitary<Qubit>>(typeof(global::Microsoft.Quantum.Intrinsic.H));
            this.Reset__ = this.__Factory__.Get<ICallable<Qubit, QVoid>>(typeof(global::Microsoft.Quantum.Intrinsic.Reset));
        }

        public override IApplyData __DataIn__((Result,Qubit) data) => new In(data);
        public override IApplyData __DataOut__(QVoid data) => data;
        public static System.Threading.Tasks.Task<QVoid> Run(IOperationFactory __m__, Result r, Qubit q)
        {
            return __m__.Run<_001342c68c374a11b857653cfc34cd36_CompareMeasurementResult, (Result,Qubit), QVoid>((r, q));
        }
    }
}

@rmshaffer
Copy link
Contributor

rmshaffer commented Oct 5, 2020

@bettinaheim Is my investigation above is enough for you to figure out what's going wrong here? Please let me know if I can provide any more information to help diagnose.

Please note that microsoft/iqsharp#266 is a relatively bad bug that will be fixed by this change, so from that perspective it would be great to get this addressed soon.

@bamarsha bamarsha added this to the October 2020 milestone Oct 7, 2020
@bettinaheim
Copy link
Contributor Author

bettinaheim commented Oct 15, 2020

@bettinaheim Is my investigation above is enough for you to figure out what's going wrong here? Please let me know if I can provide any more information to help diagnose.

Please note that microsoft/iqsharp#266 is a relatively bad bug that will be fixed by this change, so from that perspective it would be great to get this addressed soon.

"Specifically, our call to ProjectManager.LoadReferencedAssemblies() returns an empty dictionary"
@rmshaffer And it doesn't without this change? That is very odd, since this change would have nothing to do with the reference loading. Are you sure that the reference is compiling correctly? Maybe something inside the reference is using a reserved underscore pattern?

@rmshaffer
Copy link
Contributor

And it doesn't without this change?

That's correct. Without this change, the reference loads correctly and the test passes.

Are you sure that the reference is compiling correctly?

There are no compilation errors, and the only warning is the expected EntryPointInLibrary warning. My previous comment includes the C# compilation output with this change.

To help compare before/after, here is a diff of the C# compilation output before (left) and after (right) this change:
https://www.diffchecker.com/s42zJdpX

You can see that with this change, the compilation is considerably different. I assume that's because the rewrite steps are actually running, now that the EntryPointInLibrary error has been reduced to a warning. The new compilation contains symbols like _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult and _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult__.

@bettinaheim
Copy link
Contributor Author

bettinaheim commented Oct 16, 2020

And it doesn't without this change?

That's correct. Without this change, the reference loads correctly and the test passes.

Are you sure that the reference is compiling correctly?

There are no compilation errors, and the only warning is the expected EntryPointInLibrary warning. My previous comment includes the C# compilation output with this change.

To help compare before/after, here is a diff of the C# compilation output before (left) and after (right) this change:
https://www.diffchecker.com/s42zJdpX

You can see that with this change, the compilation is considerably different. I assume that's because the rewrite steps are actually running, now that the EntryPointInLibrary error has been reduced to a warning. The new compilation contains symbols like _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult and _001342c68c374a11b857653cfc34cd36_CompareMeasurementResult__.

@rmshaffer It looks like the problem is indeed that this is the first time now that an autogenerated operation (which has not position information) is deserialized via the header attributes. I am looking into it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert reserved character sequence warnings into errors Downgrade entry point in library error to warning

7 participants