All Projects → Renmusxd → RustQIP

Renmusxd / RustQIP

Licence: MIT license
Quantum computing using rust. Efficient and a borrow-checked no cloning theorem!

Programming Languages

rust
11053 projects
shell
77523 projects

Projects that are alternatives of or similar to RustQIP

quantumcat
quantumcat is a platform-independent, open-source, high-level quantum computing library, which allows the quantum community to focus on developing platform-independent quantum applications without much effort.
Stars: ✭ 18 (-83.02%)
Mutual labels:  quantum-computing
qisjob
Qiskit Job Control
Stars: ✭ 24 (-77.36%)
Mutual labels:  quantum-computing
quantumjava
Samples related to "Quantum Computing for Java Developers"
Stars: ✭ 86 (-18.87%)
Mutual labels:  quantum-computing
pennylane-lightning
The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++ for use with PennyLane
Stars: ✭ 28 (-73.58%)
Mutual labels:  quantum-computing
QuantumComputing
Collection of Tutorials and other Quantum Computer programming related things.
Stars: ✭ 120 (+13.21%)
Mutual labels:  quantum-computing
qubovert
The one-stop package for formulating, simulating, and solving problems in boolean and spin form
Stars: ✭ 19 (-82.08%)
Mutual labels:  quantum-computing
qcl
Quantum Computation Language port from http://tph.tuwien.ac.at/~oemer/qcl.html
Stars: ✭ 29 (-72.64%)
Mutual labels:  quantum-computing
BetaVQE.jl
Solving Quantum Statistical Mechanics with Variational Autoregressive Networks and Quantum Circuits
Stars: ✭ 27 (-74.53%)
Mutual labels:  quantum-computing
jet
Jet is a cross-platform library for simulating quantum circuits using tensor network contractions.
Stars: ✭ 34 (-67.92%)
Mutual labels:  quantum-computing
Quantum-Computing-Opportunities
Moved to Gitlab
Stars: ✭ 43 (-59.43%)
Mutual labels:  quantum-computing
QI
Quantum information mathematica package
Stars: ✭ 26 (-75.47%)
Mutual labels:  quantum-computing
quil
Specification of Quil: A Practical Quantum Instruction Set Architecture
Stars: ✭ 80 (-24.53%)
Mutual labels:  quantum-computing
forest-benchmarking
A library for quantum characterization, verification, validation (QCVV), and benchmarking using pyQuil.
Stars: ✭ 41 (-61.32%)
Mutual labels:  quantum-computing
cirq-on-iqm
Cirq adapter for IQM's quantum computers
Stars: ✭ 21 (-80.19%)
Mutual labels:  quantum-computing
unitaryhack
Rules and information for the 2021 unitaryHACK event hosted by @unitaryfund
Stars: ✭ 16 (-84.91%)
Mutual labels:  quantum-computing
pulsemaker
A Python widget library for designing pulses and pulse schedules for quantum computing hardware. Can be used in Jupyter notebooks, JupyterLab, and the IPython kernel.
Stars: ✭ 19 (-82.08%)
Mutual labels:  quantum-computing
cusp cirq demo
Demonstration of CUSP algorithm using Cirq
Stars: ✭ 35 (-66.98%)
Mutual labels:  quantum-computing
QuantumClifford.jl
Clifford circuits, graph states, and other quantum Stabilizer formalism tools.
Stars: ✭ 48 (-54.72%)
Mutual labels:  quantum-computing
Quantum-Computing-Resources
This repository contains the best resources for learning practical quantum computing. This repository will be updated frequently.
Stars: ✭ 60 (-43.4%)
Mutual labels:  quantum-computing
Quantum-Machine-Learning
This repository contains implementations of Quantum Machine Learning algorithms, feature maps, variational circuits and research papers.
Stars: ✭ 47 (-55.66%)
Mutual labels:  quantum-computing

RustQIP

Quantum Computing library leveraging graph building to build efficient quantum circuit simulations.

qip on crates.io qip docs unsafe forbidden

See all the examples in the examples directory.

PRs welcome

Rust is a great language for quantum computing with gate models because the borrow checker is very similar to the No-cloning theorem.

See all the examples in the examples directory of the Github repository.

Example (CSWAP)

Here's an example of a small circuit where two groups of Registers are swapped conditioned on a third. This circuit is very small, only three operations plus a measurement, so the boilerplate can look quite large in comparison, but that setup provides the ability to construct circuits easily and safely when they do get larger.

use qip::prelude::*;
use std::num::NonZeroUsize;

// Make a new circuit builder.
let mut b = LocalBuilder::<f64>::default();
let n = NonZeroUsize::new(3).unwrap();

// Make three registers of sizes 1, 3, 3 (7 qubits total).
let q = b.qubit();  // Same as b.register(1)?;
let ra = b.register(n);
let rb = b.register(n);

// Define circuit
// First apply an H to q
let q = b.h(q);
// Then swap ra and rb, conditioned on q.
let mut cb = b.condition_with(q);
let (ra, rb) = cb.swap(ra, rb) ?;
let q = cb.dissolve();
// Finally apply H to q again.
let q = b.h(q);

// Add a measurement to the first qubit, save a reference so we can get the result later.
let (q, m_handle) = b.measure(q);

// Now q is the end result of the above circuit, and we can run the circuit by referencing it.

// Run circuit with a given precision.
let (_, measured) = b.calculate_state_with_init([( & ra, 0b000), ( & rb, 0b001)]);

// Lookup the result of the measurement we performed using the handle, and the probability
// of getting that measurement.
let (result, p) = measured.get_measurement(m_handle);

// Print the measured result
println!("Measured: {:?} (with chance {:?})", result, p);

The Program Macro

While the borrow checker included in rust is a wonderful tool for checking that our registers are behaving, it can be cumbersome. For that reason qip also includes a macro which provides an API similar to that which you would see in quantum computing textbooks. This is guarded behind the macros feature.

use qip::prelude::*;
use std::num::NonZeroUsize;
use qip_macros::program;

fn gamma<B>(b: &mut B, ra: B::Register, rb: B::Register) -> CircuitResult<(B::Register, B::Register)>
    where B: AdvancedCircuitBuilder<f64>
{
    let (ra, rb) = b.toffoli(ra, rb)?;
    let (rb, ra) = b.toffoli(rb, ra)?;
    Ok((ra, rb))
}

let n = NonZeroUsize::new(3).unwrap();
let mut b = LocalBuilder::default();
let ra = b.register(n);
let rb = b.register(n);

let (ra, rb) = program!(&mut b; ra, rb;
    // Applies gamma to |ra[0] ra[1]>|ra[2]>
    gamma ra[0..2], ra[2];
    // Applies gamma to |ra[0] rb[0]>|ra[2]>
    // Notice ra[0] and rb[0] are grouped by brackets.
    gamma [ra[0], rb[0]], ra[2];
    // Applies gamma to |ra[0]>|rb[0] ra[2]>
    gamma ra[0], [rb[0], ra[2]];
    // Applies gamma to |ra[0] ra[1]>|ra[2]> if rb == |111>
    control gamma rb, ra[0..2], ra[2];
    // Applies gamma to |ra[0] ra[1]>|ra[2]> if rb == |110> (rb[0] == |0>, rb[1] == 1, ...)
    control(0b110) gamma rb, ra[0..2], ra[2];
)?;

We can also apply this to functions which take other arguments. Here gamma takes a boolean argument skip which is passed in before the registers. The arguments to functions in the program macro may not reference the input registers

use qip::prelude::*;
use std::num::NonZeroUsize;
use qip_macros::program;

fn gamma<B>(b: &mut B, skip: bool, ra: B::Register, rb: B::Register) -> CircuitResult<(B::Register, B::Register)>
    where B: AdvancedCircuitBuilder<f64>
{
    let (ra, rb) = b.toffoli(ra, rb)?;
    let (rb, ra) = if skip {
        b.toffoli(rb, ra)?
    } else {
        (rb, ra)
    };
    Ok((ra, rb))
}
let n = NonZeroUsize::new(3).unwrap();
let mut b = LocalBuilder::default();
let ra = b.register(n);
let rb = b.register(n);

let (ra, rb) = program!(&mut b; ra, rb;
    gamma(true) ra[0..2], ra[2];
    gamma(0 == 1) ra[0..2], ra[2];
)?;

The Invert Macro

It's often useful to define functions of registers as well as their inverses, the #[invert] macro automates much of this process.

use qip::prelude::*;
use std::num::NonZeroUsize;
use qip_macros::*;
use qip::inverter::Invertable;

// Make gamma and its inverse: gamma_inv
#[invert(gamma_inv)]
fn gamma<B>(b: &mut B, ra: B::Register, rb: B::Register) -> CircuitResult<(B::Register, B::Register)>
    where B: AdvancedCircuitBuilder<f64> + Invertable<SimilarBuilder=B>
{
    let (ra, rb) = b.toffoli(ra, rb)?;
    let (rb, ra) = b.toffoli(rb, ra)?;
    Ok((ra, rb))
}

let n = NonZeroUsize::new(3).unwrap();
let mut b = LocalBuilder::default();
let ra = b.register(n);
let rb = b.register(n);

let (ra, rb) = program!(&mut b; ra, rb;
    gamma ra[0..2], ra[2];
    gamma_inv ra[0..2], ra[2];
)?;

To invert functions with additional arguments, we must list the non-register arguments.

use qip::prelude::*;
use std::num::NonZeroUsize;
use qip_macros::*;
use qip::inverter::Invertable;

// Make gamma and its inverse: gamma_inv
#[invert(gamma_inv, skip)]
fn gamma<B>(b: &mut B, skip: bool, ra: B::Register, rb: B::Register) -> CircuitResult<(B::Register, B::Register)>
    where B: AdvancedCircuitBuilder<f64> + Invertable<SimilarBuilder=B>
{
    let (ra, rb) = b.toffoli(ra, rb)?;
    let (rb, ra) = if skip {
        b.toffoli(rb, ra)?
    } else {
        (rb, ra)
    };
    Ok((ra, rb))
}

let n = NonZeroUsize::new(3).unwrap();
let mut b = LocalBuilder::default();
let ra = b.register(n);
let rb = b.register(n);

let (ra, rb) = program!(&mut b; ra, rb;
    gamma(true) ra[0..2], ra[2];
    gamma_inv(true) ra[0..2], ra[2];
)?;
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].