Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A gate-based quantum circuit simulator.

License

NotificationsYou must be signed in to change notification settings

a-barlow/quantr

Crates.ioStatic BadgeGitHub Workflow Status (with event)GitHub Workflow Status (with event)docs.rsCrates.ioCrates.io

This crate is not production ready and so shouldnot be consideredstable, nor produce correct answers. It is still under heavydevelopment and requires many more optimisations. Pleasealways check answers withother simulations if you areintending to use quantr for projects.

A Rust library crate that simulates gate-based quantum circuits withfocus on memory efficiency and accessibility.

This crate allows the user to build quantum circuits by adding columnsof gates via various methods. Once the circuit has been built, then itcan be simulated, which attaches the register |00..0> resulting in asuperposition that can be measured. Quantr has primarily been built forthe simulation of pure states.

For a brief example of using quantr, see thequick start guide which walks through animplementation of Grover's algorithm.

Defining features

  • Aimed to be accessible for beginners in Rust.
  • The distinction between physical observables and non-physicalobservables that can be extracted from the circuit is made clear,where the latter is still possible to retrieve.
  • Prints the circuit diagram to the terminal, or saves it to a textfile, as a UTF-8 string.
  • Custom gates can be implemented easily by giving their explicitmappings on product states. This allows the user to avoid representingthe gates as matrices.
  • Custom gates do not have to be unitary, allowing forsome quantumchannel to be implemented.
  • Can simulate circuits up to ~16 qubits within a tractable time.
  • Only safe Rust code is used, and the only dependencies are thefastrand (2.1.0) crate,num_complex (0.4.6), and theirsub-dependencies.

Usage

An example of simulating and printing a two qubit circuit:

use quantr::{Circuit,Gate,Printer,Measurement::Observable};fnmain(){letmut quantum_circuit:Circuit =Circuit::new(2).unwrap();    quantum_circuit.add_gates(&[Gate::H,Gate::Y]).unwrap().add_gate(Gate::CNot(0),1).unwrap();letmut printer =Printer::new(&quantum_circuit);    printer.print_diagram();// The above prints the following:// ┏━━━┓// ┨ H ┠──█──// ┗━━━┛  │//        │// ┏━━━┓┏━┷━┓// ┨ Y ┠┨ X ┠// ┗━━━┛┗━━━┛let simulated_circuit = quantum_circuit.simulate();// Below prints the number of times that each state was observered// over 500 measurements of superpositions.ifletObservable(bin_count) = simulated_circuit.measure_all(500){println!("[Observable] Bin count of observed states.");for(state, count)in bin_count{println!("|{}> observed {} times", state, count);}}}

A more detailed example of using quantr is given in thequick startguide.

Limitations (currently)

  • No noise consideration, however this could be (albeit tediously)implemented through the custom gates.
  • No parallelisation option.
  • No ability to add classical wires nor gates that measure asingle wire of a quantum circuit. Only one method is given that ineffect attaches a measurement gate at the end of all qubit wires.
  • Designed primarily for the simulation of pure state vectors.Although, through the use of custom gates some quantum channels can beimplemented. For an example, seeexamples/post_select.rs.

Conventions

The ordering of the wires labelling the product states in thecomputational basis is defined as:

|a⟩ ──── |b⟩ ────  ⟺ |a,b,c,⋯⟩ ≡ |a⟩⊗|b⟩⊗|c⟩⊗⋯ |c⟩ ──── ⋮    ⋮

When defining a custom function that depends on the position of controlnodes to define gates (such as the CNot and Toffoli gates), it must bedefined so that the most far right state of the product state, isassumed to be the gate that is 'activated'. In general, it is better toassume that the custom function doesn't define control nodes, but ratherit extends the dimension of the function's domain. Lastly, it should benoted that there are no checks on the custom gate for being a validquantum channel.

Documentation

The Quantr Book is plannedto serve as extended documentation to quantr, such as explaining themotivations behind chosen algorithms. For now, it only contains thestart guide, and some preliminary results of the memory efficiency ofquantr.

For the online code documentation, please refer tocrates.io. This can also be built andopened in your favourite web browser locally by cloning the project,moving into the directory, and runningcargo doc --open.

Other quantum computer simulators

Another, and more stable, quantum circuit simulator written in Rust isSpinoza.

The websiteAre We Quantum Yet(checked 24/10/23) lists all things quantum computing in Rust.

A useful and very practical simulator for learning quantum computing isQuirk. It's a real-time online simulatorthat interfaces via drag-and-drop gates. Note that the labelling of thestates in the computational basis in Quirk is reversed when compared toquantr's labelling of such states.

Licence

Quantr is licensed under the EUPL-1.2 or later. You may obtain a copy ofthe licence athttps://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. A copyof the EUPL-1.2 licence in English is given inLICENCE.txt which is found in the root of thisrepository. Details of the licenses of third party software, and thequantr project, can be found inCOPYRIGHT.txt.

About

A gate-based quantum circuit simulator.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp