pub struct QuestEnv(/* private fields */);
Expand description
Information about the QuEST
environment.
In practice, this holds info about MPI ranks and helps to hide MPI initialization code.
Implementations§
Source§impl QuestEnv
impl QuestEnv
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/grovers_search.rs (line 69)
68fn main() -> Result<(), QuestError> {
69 let env = &QuestEnv::new();
70
71 let num_reps = (PI / 4.0 * (NUM_ELEMS as Qreal).sqrt()).ceil() as usize;
72 println!(
73 "num_qubits: {NUM_QUBITS}, num_elems: {NUM_ELEMS}, num_reps: \
74 {num_reps}"
75 );
76 // randomly choose the element for which to search
77 let mut rng = rand::thread_rng();
78 let sol_elem = rng.gen_range(0..NUM_ELEMS);
79
80 // FIXME
81 const N: i32 = NUM_QUBITS;
82 // prepare |+>
83 let mut qureg = Qureg::<'_>::try_new(N, env)?;
84 qureg.init_plus_state();
85 // use all qubits in the register
86 let qubits = &(0..NUM_QUBITS).collect::<Vec<_>>();
87
88 // apply Grover's algorithm
89 (0..num_reps).try_for_each(|_| {
90 apply_oracle(&mut qureg, qubits, sol_elem)
91 .and(apply_diffuser(&mut qureg, qubits))
92 .and(qureg.get_prob_amp(sol_elem))
93 .map(|prob| {
94 println!("prob of solution |{sol_elem}> = {:.8}", prob);
95 })
96 })
97}
More examples
examples/entanglement.rs (line 16)
14fn main() -> Result<(), QuestError> {
15 // Initialize QuEST environment and report to screen
16 let env = &QuestEnv::new();
17 env.report_quest_env();
18
19 // Create a 2-qubit register and report its parameters
20 let mut qureg = Qureg::try_new(2, env).expect("cannot allocate new Qureg");
21 qureg.report_qureg_params();
22 // Initialize |00> state and print out the state to screen
23 qureg.init_zero_state();
24 qureg.report_state_to_screen(0);
25
26 // Prepare a Bell state `|00> + |11>`: apply Hadamard gate
27 // on qubit 0, then NOT on qubit 1, controlled by qubit 0.
28 println!("---\nPrepare Bell state: |00> + |11>");
29 qureg.hadamard(0).and(qureg.controlled_not(0, 1))?;
30
31 // Measure both qubits
32 let outcome0 = qureg.measure(0)?;
33 let outcome1 = qureg.measure(1)?;
34 println!("Qubit \"0\" measured in state: |{outcome0}>");
35 println!("Qubit \"1\" measured in state: |{outcome1}>");
36
37 // Because the state was entangled, the outcomes
38 // should always be the same
39 if outcome0 == outcome1 {
40 println!("They match!");
41 Ok(())
42 } else {
43 panic!("qubits in Bell state should be perfectly correlated");
44 }
45
46 // At this point both `qureg` and `env` are dropped and
47 // the allocated memory is freed.
48}
Sourcepub fn sync(&self)
pub fn sync(&self)
Sync environment in distributed mode.
Guarantees that all code up to the given point has been executed on all nodes (if running in distributed mode).
§Examples
let env = QuestEnv::new();
env.sync();
Sourcepub fn report_quest_env(&self)
pub fn report_quest_env(&self)
Report information about the QuEST
environment.
The information if printed to standard output.
See QuEST API for more information.
Examples found in repository?
examples/entanglement.rs (line 17)
14fn main() -> Result<(), QuestError> {
15 // Initialize QuEST environment and report to screen
16 let env = &QuestEnv::new();
17 env.report_quest_env();
18
19 // Create a 2-qubit register and report its parameters
20 let mut qureg = Qureg::try_new(2, env).expect("cannot allocate new Qureg");
21 qureg.report_qureg_params();
22 // Initialize |00> state and print out the state to screen
23 qureg.init_zero_state();
24 qureg.report_state_to_screen(0);
25
26 // Prepare a Bell state `|00> + |11>`: apply Hadamard gate
27 // on qubit 0, then NOT on qubit 1, controlled by qubit 0.
28 println!("---\nPrepare Bell state: |00> + |11>");
29 qureg.hadamard(0).and(qureg.controlled_not(0, 1))?;
30
31 // Measure both qubits
32 let outcome0 = qureg.measure(0)?;
33 let outcome1 = qureg.measure(1)?;
34 println!("Qubit \"0\" measured in state: |{outcome0}>");
35 println!("Qubit \"1\" measured in state: |{outcome1}>");
36
37 // Because the state was entangled, the outcomes
38 // should always be the same
39 if outcome0 == outcome1 {
40 println!("They match!");
41 Ok(())
42 } else {
43 panic!("qubits in Bell state should be perfectly correlated");
44 }
45
46 // At this point both `qureg` and `env` are dropped and
47 // the allocated memory is freed.
48}
Sourcepub fn get_environment_string(&self) -> Result<String, QuestError>
pub fn get_environment_string(&self) -> Result<String, QuestError>
Get a string containing information about the runtime environment,
§Examples
let env = &QuestEnv::new();
let env_str = env.get_environment_string().unwrap();
assert!(env_str.contains("OpenMP="));
assert!(env_str.contains("threads="));
assert!(env_str.contains("MPI="));
assert!(env_str.contains("ranks="));
assert!(env_str.contains("CUDA="));
See QuEST API for more information.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for QuestEnv
impl RefUnwindSafe for QuestEnv
impl Send for QuestEnv
impl Sync for QuestEnv
impl Unpin for QuestEnv
impl UnwindSafe for QuestEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more