### 2 releases

Uses old Rust 2015

0.1.1 | Feb 7, 2018 |
---|---|

0.1.0 | Feb 7, 2018 |

#**396** in Simulation

**MIT**license

20KB

428 lines

# Rusq

Quantum computing simulator in Rust

## Overview

Rusq is a library to simulate a gate-type quantum computer written purely in Rust.

The Rusq design is highly inspired by Q#. Basically, only "physically safe" operation is implemented - no non-physical information like the amplitude of a wavefunction can be obtained by default.

### Feature

- Measurement and projection
- Basic quantum gates
- $X, Y, Z$, Hadamard, identity, CNOT, CCNOT

## How to use

First, add the following to `Cargo.toml`

`[``dependencies``]`
`rusq = { version = "*", git ``=` `"`https://github.com/hajifkd/rusq.git`"` }

For example codes, check out the following section.

## Examples

For instance, you can make EPR pair like this:

`extern` `crate` rusq`;`
`use` `rusq``::``prelude``::``*``;`
`fn` `set``(``sim``:` `&``mut` QuantumSimulator, `qubit``:` `&`Qubit, `r``:` MeasuredResult`)`` ``{`
`if` sim`.``measure``(`qubit`)` `!=` r `{`
sim`.`X`(`qubit`)``;`
`}`
`}`
`fn` `main``(``)`` ``{`
`let` `mut` sim `=` `QuantumSimulator``::`new`(``2``)``;`
`let` qubits `=` sim`.``get_qubits``(``)``;`
`let` measure_count `=` `10000``;`
`for` `_` `in` `0``..`measure_count `{`
`set``(``&``mut` sim`,` `&`qubits`[``0``]``,` `MeasuredResult``::`Zero`)``;`
`set``(``&``mut` sim`,` `&`qubits`[``1``]``,` `MeasuredResult``::`Zero`)``;`
sim`.`H`(``&`qubits`[``0``]``)``;`
sim`.``CNOT``(``&`qubits`[``0``]``,` `&`qubits`[``1``]``)``;`
`assert_eq!``(`sim`.``measure``(``&`qubits`[``0``]``)``,` sim`.``measure``(``&`qubits`[``1``]``)``)``;`
`}`
`}`

For other kinds of examples, check tests directory. Pull requests to implement another examples of quantum computation is welcome.

## License

MIT

#### Dependencies

~2.5MB

~41K SLoC