This repository was archived by the owner on Jun 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackend.rs
53 lines (48 loc) · 1.67 KB
/
backend.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Basic backend implementation that doesn't do anything, to be used for
//! testing and perhaps as an example. Measurements return random values with
//! a 50/50 chance.
use dqcsim::{
common::types::{
ArbData, PluginMetadata, PluginType, QubitMeasurementResult, QubitMeasurementValue,
},
debug, info,
plugin::{definition::PluginDefinition, state::PluginState},
};
use std::env;
fn main() {
let mut definition = PluginDefinition::new(
PluginType::Backend,
PluginMetadata::new("Null backend", "TU Delft QCE", "0.1.0"),
);
definition.initialize = Box::new(|_state, arb_cmds| {
info!("Running null backend initialization callback");
for arb_cmd in arb_cmds {
debug!("{}", arb_cmd);
}
Ok(())
});
definition.gate = Box::new(|state, gate| {
let measured_qubits = gate.get_measures();
if measured_qubits.is_empty() {
debug!("Received a gate that doesn't measure anything");
Ok(vec![])
} else {
debug!(
"Received a gate that measures the following qubits: {:?}",
measured_qubits
);
Ok(measured_qubits
.iter()
.map(|q| {
let value = if state.random_f64() < 0.5 {
QubitMeasurementValue::Zero
} else {
QubitMeasurementValue::One
};
QubitMeasurementResult::new(*q, value, ArbData::default())
})
.collect())
}
});
PluginState::run(&definition, env::args().nth(1).unwrap()).unwrap();
}