Building and modifying Q# Libraries

倾然丶 夕夏残阳落幕 提交于 2021-02-10 17:50:31

问题


How can the libraries (https://github.com/microsoft/QuantumLibraries) be modified locally? For example, creating references to the Quantum Chemistry library only uses the prebuilt DLL. Is there a way to reference the local Quantum Chem library, make edits to that code, and see those changes reflected? Thanks.


回答1:


The Quantum Development Kit uses the .NET Core SDK to find and link together the various Q# libraries, in particular through C# project files (*.csproj). Within a C# project file, you can declare a dependency to another library using either a package reference or a project reference. Package references (e.g.: <PackageReference Include="Microsoft.Quantum.Standard" Version="0.7.1905.3109" />) instruct the .NET Core SDK to download a package from NuGet.org with a given name and version and then link to all DLLs contained in the project. By contrast, project references (e.g.: <ProjectReference Include="..\..\..\Standard\src\Standard.csproj" />) instruct the .NET Core SDK to first build the referenced project, then link to its DLL.

To use the libraries built from https://github.com/microsoft/QuantumLibraries, we generally recommend using package references, as project references across different repositories can be difficult to manage — you need for the path to a project file to be predictable, which can be hard to do in that case. This is why we've taken the strategy with the QuantumLibraries repo that references within the repo are project references, while references to other parts of the Quantum Development Kit are package references. For example, the chemistry library runtime uses a project reference to link to the version of the standard libraries in the same repo, but samples in https://github.com/microsoft/Quantum use package references:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <PlatformTarget>x64</PlatformTarget>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.1.1" />
        <PackageReference Include="Microsoft.Quantum.Standard" Version="0.7.1905.3109" />
        <PackageReference Include="Microsoft.Quantum.Chemistry" Version="0.7.1905.3109" />
        <PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.7.1905.3109" />
        <PackageReference Include="Microsoft.Quantum.Research" Version="0.7.1905.3109" />
    </ItemGroup>

    <ItemGroup>
        <Compile Update="Program.cs">
            <CopyToOutputDirectory>Never</CopyToOutputDirectory>
        </Compile>
    </ItemGroup>
</Project>

That said, if you're locally testing a contribution you'd like to make to the Quantum Development Kit, linking to the Q# standard and chemistry libraries using project references can sometimes be helpful until a new package including your contribution is built and published to NuGet.org.



来源:https://stackoverflow.com/questions/56876281/building-and-modifying-q-libraries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!