-
Notifications
You must be signed in to change notification settings - Fork 1
41 visualization #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
41 visualization #46
Changes from 5 commits
d6e74ea
6028ad2
6427129
9892c69
64d257c
465b330
10137fe
53e4037
1dab1df
be06cdc
633158a
e63f18b
5da88f3
ff9d3bc
0b5d2d4
2c4bce9
ffe6f30
8eae13b
b739ca7
d0aa460
ff982f1
2f9c90a
705cf68
f7b8a55
367d185
832716f
e5694c4
695551f
5d0cc53
1f0a1e6
f9502fe
5a2fa61
26f053c
201ae27
1bcbf46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| use std::collections::VecDeque; | ||
|
|
||
| use bitvec::bitvec; | ||
| use bitvec::prelude::Lsb0; | ||
| use syn::data_structures::{CliffordTableau, PauliPolynomial, PauliString}; | ||
| use syn::ir::pauli_exponential::PauliExponential; | ||
|
|
||
| fn main() { | ||
| // test tableaus | ||
| // Stab: ZZZ, -YIY, XIX | ||
| // Destab: -IXI, XXI, IYY | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these stabilizers and destabilizers correspond ot the tableau you are creating in the code
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it in the latest commit |
||
| // qubit 1x: ZYI | ||
| // qubit 1z: IZZ | ||
| let pauli_1 = PauliString::from_text("ZYIIZZ"); | ||
| // qubit 2x: ZIX | ||
| // qubit 2z: XII | ||
| let pauli_2 = PauliString::from_text("ZIXXII"); | ||
| // qubit 3x: ZYY | ||
| // qubit 3z: IIZ | ||
| let pauli_3 = PauliString::from_text("ZYYIIZ"); | ||
| let signs = bitvec![0, 1, 0, 1, 0, 0]; | ||
| let my_tableaus = CliffordTableau::from_parts(vec![pauli_1, pauli_2, pauli_3], signs); | ||
|
tungbuidang marked this conversation as resolved.
Outdated
|
||
| CliffordTableau::visualize_tableaus(&my_tableaus); | ||
|
|
||
| //test pauli polynomial | ||
|
|
||
| let ham = vec![("IXYZ", 0.3), ("XXII", 0.7), ("YYII", 0.12)]; | ||
| let pp = PauliPolynomial::from_hamiltonian(ham); | ||
| pp.visualize_pauli_polynomial(); | ||
|
|
||
| // visualize_pauli_exponential_simple(&pe); | ||
| let ham = vec![("IZZZ", 0.3)]; | ||
| let pp = PauliPolynomial::from_hamiltonian(ham); | ||
| let ct = CliffordTableau::new(4); | ||
| let pe = PauliExponential::new(VecDeque::from([pp]), ct); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reuse the pp and tableau from before |
||
| pe.visualize_pauli_exponential(); | ||
|
|
||
| //visualize_pauli_exponential complex | ||
| let ham = vec![("IXYZ", 0.3), ("XXII", 0.7), ("YYII", 0.12)]; | ||
|
|
||
| let pauli_polynomial = PauliPolynomial::from_hamiltonian(ham); | ||
| let clifford_tableau = CliffordTableau::new(4); | ||
| let complex_pe = PauliExponential::new(VecDeque::from([pauli_polynomial]), clifford_tableau); | ||
| complex_pe.visualize_pauli_exponential(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,14 @@ impl CliffordTableau { | |
| self.size | ||
| } | ||
|
|
||
| pub fn pauli_column(&self, i: usize) -> &PauliString { | ||
| &self.pauli_columns[i] | ||
| } //why does column does not work and I need a new getter method ? | ||
|
Ectras marked this conversation as resolved.
Outdated
|
||
|
|
||
| pub fn signs(&self) -> &BitVec { | ||
| &self.signs | ||
| } | ||
|
|
||
| pub(crate) fn x_signs(&self) -> BitVec { | ||
| let n = self.size(); | ||
| self.signs[0..n].to_bitvec() | ||
|
|
@@ -177,6 +185,49 @@ impl CliffordTableau { | |
| .collect::<Vec<_>>(); | ||
| self.pauli_columns = sorted_pauli_columns; | ||
| } | ||
|
|
||
| pub fn visualize_tableaus(&self) { | ||
|
tungbuidang marked this conversation as resolved.
Outdated
|
||
| println!("Clifford Tableau ({} qubits):", self.size()); | ||
|
tungbuidang marked this conversation as resolved.
Outdated
|
||
| print!(" ||"); | ||
| for i in 0..self.size() { | ||
| print!(" X{} Z{}|", i + 1, i + 1); | ||
| } | ||
| println!(); | ||
| print!("+/- ||"); | ||
| for i in 0..self.signs().len() { | ||
| if self.signs().get(i).map(|b| *b) == Some(true) { | ||
|
tungbuidang marked this conversation as resolved.
Outdated
|
||
| print!(" +"); | ||
| } else { | ||
| print!(" -"); | ||
| } | ||
| print!(" "); | ||
| if i % 2 != 0 { | ||
| print!("|"); | ||
| } | ||
| } | ||
| println!(); | ||
|
|
||
| for i in 0..self.size() { | ||
|
tungbuidang marked this conversation as resolved.
Outdated
|
||
| print!("QB{} ||", i + 1); | ||
| let column = self.pauli_column(i).to_string(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, it's a bit risky to rely on the string representation of |
||
| let mut out = String::new(); | ||
| let mut count = 0; | ||
| for ch in column.chars() { | ||
| if ch != ' ' { | ||
| count += 1; | ||
| out.push(ch); | ||
| if count % 2 == 1 { | ||
| out.push(' '); | ||
| } else { | ||
| out.push_str(" |"); | ||
| } | ||
| } else { | ||
| out.push(' '); | ||
| } | ||
| } | ||
| println!(" {} ", out); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl HasAdjoint for CliffordTableau { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.