This is a utility library I am writing as I learn Q# and quantum programming. It comprises functions I have found helpful that do not currently appear (as far as I can see) in the standard library. Functions cover the following areas:
- Complex numbers:
Complex.qs
, namespaceUtilities.Complex
- Vectors:
Vectors.qs
, namespaceUtilities.Vectors
- Matrices:
Matrices.qs
and theMatrices
folder, namespaceUtilities.Matrices
- Higher order functions:
HigherOrderFunctions.qs
The Q# part of the program can be run in VSCode provided that the Azure Quantum Development Kit (QDK) is installed.
The tests are written in Python and run with pytest
. To install Python with its dependencies (qsharp
, numpy
and pytest
) (and a currently-empty package qsharp-utilitiies
):
-
Clone or download the repository.
-
Navigate into the cloned / downloaded repository.
-
Make sure the virtual environment has been activated, e.g. on Linux:
source env/bin/activate
-
Install with
pip
:pip install .
-
Alternatively, from within the cloned repository, install at the
user
level with:pip install . --user
-
If you wish to install
mypy
for type checking (in addition to the other dependencies), run:pip install .[dev]
You can use this library as a dependency in your own project. To do this, your qsharp.json
file should (minimally) contain the following information:
{
"author": "your-name-here",
"dependencies": {
"QsUtils": {
"path": "path/to/dependency"
}
}
}
To import from this library, prefix the module path you wish to import with the name for your dependency, in this case QsUtils
, e.g.:
import Std.Math.*;
import QsUtils.Utilities.Complex.*;
@EntryPoint()
function Main() : Complex {
ToC(1.)
}
Full instructions on project structure and using dependencies can be found in the Microsoft Docs.
Produces the complex conjugate of input parameter complex
.
Complex numbers cannot be directly compared. Thus the following expression produces a type error, since the Complex struct does not support equality:
Complex(1., 1.) == Complex(1., 1.)
The EqualC
function performs this comparison:
EqualC(Complex(1., 1.), Complex(1., 1.)); // Evaluates to true
Takes a function with a pair of parameters, and returns a curried version of it, i.e. two functions taking a single parameter each. For example, whereas EqualC
has the type signature:
(Complex, Complex) -> Bool
in the following:
let equalC = Curry2(EqualC);
equalC
has the type signature:
Complex -> Complex -> Bool
Q# itself is licensed under MIT.
Python dependencies are the following:
Licenses for these dependencies are included in the LICENSES
directory.