Quantum.NET: a new quantum computing library in C#

I’ve just published the first version of my latest project, a quantum computing library in C# called Quantum.NET that allows the manipulation of qubits and the modeling of quantum circuits.

It is available as a NuGet package under Lachesis.QuantumComputing, and the source code can be found on GitHub at phbaudin/quantum-computing.

The way it works is pretty straightforward. A qubit can be created from its probability amplitudes:

Or from its amplitudes’ real and imaginary parts:

It can also be created from its colatitude and longitude on the Bloch sphere:

Shortcuts are available for notable qubits:

A qubit is a quantum register of length 1 and can be manipulated as such. The Qubit class is merely a subclass of QuantumRegister designed for ease of use:

Shortcuts are also available for notable quantum registers:

A quantum register can be created from other quantum registers (variadic constructor, also works with QuantumRegister[] and IEnumerable<QuantumRegister>):

Or from the 2n complex probability amplitudes of each of its pure states (variadic constructor, also works with Complex[] and IEnumerable<Complex>):

Quantum registers are mostly used to represent numbers and can therefore be created from integers (this will naturally generate pure states):

A quantum register can be observed and collapse into a pure state (note: use your own Random instance to avoid issues with pseudorandom number generator determinism):

Quantum gates are required to operate on quantum registers. Shortcuts are also available for notable quantum gates:

  • QuantumGate.HadamardGate
  • QuantumGate.HadamardGateOfLength(int registerLength)
  • QuantumGate.NotGate
  • QuantumGate.PauliYGate
  • QuantumGate.PauliZGate
  • QuantumGate.SquareRootNotGate
  • QuantumGate.PhaseShiftGate(double phase)
  • QuantumGate.SwapGate
  • QuantumGate.SquareRootSwapGate
  • QuantumGate.ControlledNotGate
  • QuantumGate.ControlledGate(QuantumGate gate)
  • QuantumGate.ToffoliGate
  • QuantumGate.FredkinGate
  • QuantumGate.QuantumFourierTransform(int registerLength)

Quantum gates can also be created from a bidimensional array of complex numbers:

Applying a quantum gate to a quantum register is as simple as using the multiplication operator on them:

Unary gates only operate on one qubit, binary gates on two, etc.:

Please note that this is not a literal arithmetic library. While measures have been taken to circumvent a range of errors caused by floating-point precision, the use of QuantumRegister.AlmostEquals might be required in places:

Hope you find this useful!