- Notifications
You must be signed in to change notification settings - Fork0
A gate-based quantum circuit simulator.
License
a-barlow/quantr
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
- 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.
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.
- 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, see
examples/post_select.rs.
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.
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.
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.
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
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.