page_type | languages | products | description | ||
---|---|---|---|---|---|
sample |
|
|
This sample uses the `Microsoft.Quantum.AutoSubstitution` NuGet package to provide alternative operations based on the simulator that is used. |
The Microsoft.Quantum.AutoSubstitution
NuGet package offers an attribute @SubstitutableOnTarget
that lets you replace one operation with another when using a particular simulator. For instance, decorating the operation Op
with @SubstitutableOnTarget("AltOp", "Sim")
lets the compiler perform a rewrite step that can link an operation Op
to a set of pairs of an alternative operations AltOp
and a simulator Sim
, such that AltOp
is executed as a replacement for Op
when being invoked in Sim
.
This auto substitution blog post in the Q# blog describes this sample in more detail.
First, run
dotnet run
and you should see Quantum version
as output, but when running
dotnet run -- -s ToffoliSimulator
the program prints Classical version
instead, since the alternative operation
is executed.
- AutoSubstitution.qs: The main Q# example code implementing quantum operations for this sample.
- AutoSubstitution.csproj: Main Q# project for the sample.