-
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 14 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,46 @@ | ||
| 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
|
||
|
|
||
| println!("{}", my_tableaus); | ||
|
|
||
| // test pauli polynomial | ||
|
|
||
| let ham = vec![("IXYZ", 0.3), ("XXII", 0.7), ("YYII", 0.12)]; | ||
| let pp = PauliPolynomial::from_hamiltonian(ham); | ||
| println!("{}", pp); | ||
|
|
||
| // // 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 |
||
| println!("{}", pe); | ||
|
|
||
| // //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); | ||
| println!("{}", complex_pe); | ||
|
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. then this would be redundant |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,8 @@ use std::fmt; | |
| use std::iter::zip; | ||
| use std::ops::Mul; | ||
|
|
||
| use crate::data_structures::PauliLetter; | ||
|
|
||
| use super::HasAdjoint; | ||
| use super::{ | ||
| pauli_string::{cx, PauliString}, | ||
|
|
@@ -41,6 +43,10 @@ impl CliffordTableau { | |
| self.size | ||
| } | ||
|
|
||
| pub fn signs(&self) -> &BitVec { | ||
| &self.signs | ||
| } | ||
|
|
||
| pub(crate) fn x_signs(&self) -> BitVec { | ||
| let n = self.size(); | ||
| self.signs[0..n].to_bitvec() | ||
|
|
@@ -55,7 +61,7 @@ impl CliffordTableau { | |
| &self.pauli_columns[i] | ||
| } | ||
|
|
||
| pub fn compose(&self, rhs: &Self) -> Self { | ||
| pub(crate) fn compose(&self, rhs: &Self) -> Self { | ||
| rhs.prepend(self) | ||
| } | ||
|
|
||
|
|
@@ -301,20 +307,59 @@ impl Mul for CliffordTableau { | |
|
|
||
| impl fmt::Display for CliffordTableau { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| writeln!(f, "CliffordTableau({})", self.size())?; | ||
| for pauli_column in self.pauli_columns.iter() { | ||
| writeln!(f, "{}", pauli_column)?; | ||
| write!(f, " ||")?; | ||
| for i in 0..self.size() { | ||
| write!(f, " X{} Z{}|", i + 1, i + 1)?; | ||
| } | ||
| writeln!(f)?; | ||
| write!(f, "+/- ||")?; | ||
| for (i, sign) in self.signs().iter().enumerate() { | ||
| if *sign { | ||
| write!(f, " - ")?; | ||
| } else { | ||
| write!(f, " + ")?; | ||
| } | ||
| if i % 2 != 0 { | ||
| write!(f, "|")?; | ||
| } | ||
| } | ||
| let mut sign_str = String::new(); | ||
| for bit in self.signs.iter() { | ||
| match *bit { | ||
| true => sign_str.push('-'), | ||
| false => sign_str.push('+'), | ||
| writeln!(f)?; | ||
|
|
||
| for (i, column) in self.pauli_columns.iter().enumerate() { | ||
| write!(f, "QB{} ||", i)?; | ||
| let mut out = String::new(); | ||
| let mut letter_count = 0; | ||
| for j in 0..column.len() { | ||
| // let letter = column.pauli(j); | ||
| match column.pauli(j) { | ||
|
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. It looks like you are printing the tableau transposed. i.e. the columns are printed as rows. |
||
| PauliLetter::I => { | ||
| out.push('I'); | ||
| letter_count += 1; | ||
| } | ||
| PauliLetter::X => { | ||
| out.push('X'); | ||
| letter_count += 1; | ||
| } | ||
| PauliLetter::Z => { | ||
| out.push('Z'); | ||
| letter_count += 1; | ||
| } | ||
| PauliLetter::Y => { | ||
| out.push('Y'); | ||
| letter_count += 1; | ||
| } | ||
| } | ||
| if letter_count % 2 == 1 { | ||
| out.push(' '); | ||
| } else { | ||
| out.push_str(" |"); | ||
| } | ||
| out.push(' '); | ||
| } | ||
| sign_str.push(' ') | ||
| out.push('\n'); | ||
| write!(f, " {}", out)?; | ||
| } | ||
| sign_str.pop(); | ||
| write!(f, "{}", sign_str) | ||
| writeln!(f) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1194,7 +1239,7 @@ mod tests { | |
| let ct = setup_sample_ct(); | ||
| assert_eq!( | ||
| ct.to_string(), | ||
| "CliffordTableau(3)\nZ Y I I Z Z\nZ I X X I I\nZ Y Y I I Z\n+ - + - + +" | ||
| " || X1 Z1| X2 Z2| X3 Z3|\n+/- || + - | + - | + + |\nQB0 || Z Y | I I | Z Z | \nQB1 || Z I | X X | I I | \nQB2 || Z Y | Y I | I Z | \n\n" | ||
|
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. Yeah, you are printing the transpose, which was the limitation of the debug formatter because it's easy to print the columns are rows.
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. should be correct now |
||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| use std::{iter::zip, sync::RwLock}; | ||
|
|
||
| use bitvec::vec::BitVec; | ||
| use itertools::zip_eq; | ||
| use itertools::Itertools; | ||
| use std::fmt; | ||
| use std::{iter::zip, sync::RwLock}; | ||
|
|
||
| use super::{pauli_string::PauliString, IndexType, MaskedPropagateClifford, PropagateClifford}; | ||
|
|
||
|
|
@@ -168,6 +169,32 @@ impl MaskedPropagateClifford for PauliPolynomial { | |
| self | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Display for PauliPolynomial { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| let angles = self.angles.read().unwrap(); | ||
| let string_angles = angles | ||
| .iter() | ||
| .map(|x| format!("{:.3}", x)) //force 3 decimal place for formatting | ||
| .join(" | "); | ||
| writeln!(f, "Angles | {} |", string_angles)?; | ||
| let chains = self.chains(); | ||
| for (i, pauli) in chains.iter().enumerate() { | ||
| write!(f, "Qubit {}|", i)?; | ||
| let chain_str = pauli.to_string(); | ||
| let mut out = String::new(); | ||
| for ch in chain_str.chars() { | ||
| out.push(ch); | ||
| if !ch.is_whitespace() { | ||
| out.push_str(" |"); | ||
| } | ||
| } | ||
| writeln!(f, " {}", out)?; | ||
| } | ||
| writeln!(f) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -585,4 +612,12 @@ mod tests { | |
| }; | ||
| assert_eq!(pp, pp_ref); | ||
| } | ||
| #[test] | ||
| fn test_pauli_polynomial_display() { | ||
| let pp = setup_sample_pp(); | ||
| assert_eq!( | ||
| pp.to_string(), | ||
| "Angles | 0.300 | 0.700 | 0.120 |\nQubit 0| I | X | Y |\nQubit 1| Z | Y | X |\nQubit 2| Y | I | X |\n\n" | ||
|
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. Be more consistent with the formatting wrt the tableau. "QB0" vs "Qubit 0".
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. fixed |
||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.