microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/paulimer/src/lib.rs
83lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | pub mod bits; |
| 5 | pub mod clifford; |
| 6 | pub mod operations; |
| 7 | pub mod outcome_specific_simulation; |
| 8 | pub mod pauli; |
| 9 | pub mod quantum_core; |
| 10 | pub mod setwise; |
| 11 | |
| 12 | pub use operations::UnitaryOp; |
| 13 | |
| 14 | type Tuple2<T> = (T, T); |
| 15 | type Tuple4<T> = (T, T, T, T); |
| 16 | type Tuple8<T> = (T, T, T, T, T, T, T, T); |
| 17 | type Tuple2x2<T> = Tuple2<Tuple2<T>>; |
| 18 | type Tuple4x2<T> = Tuple4<Tuple2<T>>; |
| 19 | |
| 20 | pub trait NeutralElement { |
| 21 | type NeutralElementType: 'static; |
| 22 | fn neutral_element(&self) -> Self::NeutralElementType; |
| 23 | fn default_size_neutral_element() -> Self::NeutralElementType; |
| 24 | fn neutral_element_of_size(size: usize) -> Self::NeutralElementType; |
| 25 | } |
| 26 | |
| 27 | use clifford::CliffordUnitary; |
| 28 | use pauli::SparsePauli; |
| 29 | use quantum_core::PositionedPauliObservable; |
| 30 | |
| 31 | pub trait Simulation { |
| 32 | fn pauli_exp(&mut self, sparse_pauli: &[PositionedPauliObservable]); |
| 33 | |
| 34 | fn apply_unitary(&mut self, unitary_op: UnitaryOp, support: &[usize]); |
| 35 | fn apply_clifford(&mut self, clifford: &CliffordUnitary, support: &[usize]); |
| 36 | fn apply_permutation(&mut self, permutation: &[usize], support: &[usize]); |
| 37 | |
| 38 | fn controlled_pauli( |
| 39 | &mut self, |
| 40 | observable1: &[PositionedPauliObservable], |
| 41 | observable2: &[PositionedPauliObservable], |
| 42 | ); |
| 43 | fn pauli(&mut self, observable: &[PositionedPauliObservable]); |
| 44 | fn random_bit(&mut self) -> usize; |
| 45 | |
| 46 | fn measure(&mut self, observable: &[PositionedPauliObservable]) -> usize; |
| 47 | fn measure_with_hint( |
| 48 | &mut self, |
| 49 | observable: &[PositionedPauliObservable], |
| 50 | hint: &[PositionedPauliObservable], |
| 51 | ) -> usize; |
| 52 | fn measure_sparse(&mut self, pauli: &SparsePauli) -> usize; |
| 53 | |
| 54 | fn conditional_pauli( |
| 55 | &mut self, |
| 56 | observable: &[PositionedPauliObservable], |
| 57 | outcomes: &[usize], |
| 58 | parity: bool, |
| 59 | ); |
| 60 | |
| 61 | fn assert_stabilizer(&self, observable: &[PositionedPauliObservable]); |
| 62 | fn assert_stabilizer_up_to_sign(&self, observable: &[PositionedPauliObservable]); |
| 63 | fn assert_anti_stabilizer(&self, observable: &[PositionedPauliObservable]); |
| 64 | |
| 65 | fn with_capacity(num_qubits: usize, num_outcomes: usize, num_random_outcomes: usize) -> Self; |
| 66 | |
| 67 | fn new() -> Self; |
| 68 | |
| 69 | fn num_random_outcomes(&self) -> usize; |
| 70 | fn random_outcome_indicator(&self) -> &[bool]; |
| 71 | } |
| 72 | |
| 73 | #[must_use] |
| 74 | pub fn subscript_digits(number: usize) -> String { |
| 75 | let mut res = String::new(); |
| 76 | for char in number.to_string().chars() { |
| 77 | let digit = char.to_digit(10).unwrap_or_default() as usize; |
| 78 | res.push(SUB_CHARS[digit]); |
| 79 | } |
| 80 | res |
| 81 | } |
| 82 | |
| 83 | pub const SUB_CHARS: [char; 10] = ['₀', '₁', '₂', '₃', '₄', '₅', '₆', '₇', '₈', '₉']; |
| 84 | |