Last active
April 1, 2023 17:31
-
-
Save omgbbqhaxx/5c31d0c6372f3609ac11144fb723b632 to your computer and use it in GitHub Desktop.
simple quantum hademard gates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate q1tsim; | |
use q1tsim::{circuit, gates}; | |
fn main() { | |
// The number of times this circuit is evaluated | |
let nr_runs = 8192; | |
// Create a quantum circuit with 3 quantum bits and 3 classical (measurement) | |
// bits. The circuit starts by default with all quantum bits in the |0⟩ state, | |
// so in this case |000⟩. | |
let mut circuit = circuit::Circuit::new(3, 3); | |
// Apply an X gate to all qubits after measurement | |
circuit.h(0); | |
circuit.h(1); | |
circuit.h(2); | |
circuit.measure_all(&[0, 1, 2]); | |
// Actually calculate the resulting quantum state and perform the measurements, | |
// averaging over `nr_runs` runs. | |
circuit.execute(nr_runs); | |
// And print the results. | |
let hist = circuit.histogram_string().unwrap(); | |
let mut sorted_hist = hist.iter().collect::<Vec<_>>(); | |
sorted_hist.sort_by_key(|(_, count)| *count); // Sort by count, ascending | |
for (bits, count) in sorted_hist { | |
println!("{}: {}", bits, count); | |
} | |
//println!("{:?}", hist); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment