Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d6e74ea
add some method for visualization of tableaus and pp
tungbuidang Aug 12, 2025
6028ad2
add visualization to pauli polynomial
tungbuidang Aug 13, 2025
6427129
clean up the logic for visualization
tungbuidang Aug 18, 2025
9892c69
remove unnecessary getter setter method
tungbuidang Aug 18, 2025
64d257c
added visualization to data structure in examples folder
tungbuidang Aug 18, 2025
465b330
fix some issue from pull request comments
tungbuidang Aug 20, 2025
10137fe
fix example to fit visualization case
tungbuidang Aug 21, 2025
53e4037
fix logic to true assign to - sign and false to + sign
tungbuidang Aug 21, 2025
1dab1df
add example and test for pauli polynomial
tungbuidang Aug 21, 2025
be06cdc
clean up and add Display trait to pe
tungbuidang Aug 22, 2025
633158a
clean up and add Display trait to pe
tungbuidang Aug 22, 2025
e63f18b
remove unnecessary method, make display for pp a bit more efficient b…
tungbuidang Aug 22, 2025
5da88f3
Merge remote-tracking branch 'origin' into 41-visualization
tungbuidang Aug 27, 2025
ff9d3bc
change Display function to use pauli letter instead of to_string method
tungbuidang Aug 29, 2025
0b5d2d4
Merge remote-tracking branch 'origin' into 41-visualization
tungbuidang Sep 1, 2025
2c4bce9
changed name of examples file to better match its functionality
tungbuidang Sep 1, 2025
ffe6f30
change compose function to test if python build can pass. The compile…
tungbuidang Sep 1, 2025
8eae13b
rewrite clifford tableaus Display trait to correctly print row and co…
tungbuidang Sep 2, 2025
b739ca7
update test
tungbuidang Sep 2, 2025
d0aa460
change clifford tableau display trait to use string construction, for…
tungbuidang Sep 2, 2025
ff982f1
update test
tungbuidang Sep 2, 2025
2f9c90a
fix tableaux because French
tungbuidang Sep 2, 2025
705cf68
added new display for Pauli Exponential
tungbuidang Sep 4, 2025
f7b8a55
support multi pauli polynomials printing for pauli exponential
tungbuidang Sep 10, 2025
367d185
fix pauli exponential display to not show multiple 'QB' column
tungbuidang Sep 10, 2025
832716f
add logic to correctly format clifford tableaux for big case. Also cl…
tungbuidang Sep 10, 2025
e5694c4
support print alignment of up to 99 qubits
tungbuidang Sep 11, 2025
695551f
test print empty data structure
tungbuidang Oct 21, 2025
5d0cc53
fix for merge conlfict
tungbuidang Oct 21, 2025
1f0a1e6
swap Stabilizer/Destabilizer
tungbuidang Oct 23, 2025
f9502fe
add print empty for clifford tableau and pauli polynomial
tungbuidang Oct 23, 2025
5a2fa61
fix test to pass build
tungbuidang Oct 23, 2025
26f053c
test display fix
tungbuidang Oct 24, 2025
201ae27
added printing empty logic for all data structures
tungbuidang Oct 24, 2025
1bcbf46
add some edge case for printing empty exponential
tungbuidang Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions examples/plot_data_structure.rs
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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);
Comment thread
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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();
}
51 changes: 51 additions & 0 deletions src/data_structures/clifford_tableau.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Comment thread
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()
Expand Down Expand Up @@ -177,6 +185,49 @@ impl CliffordTableau {
.collect::<Vec<_>>();
self.pauli_columns = sorted_pauli_columns;
}

pub fn visualize_tableaus(&self) {
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
println!("Clifford Tableau ({} qubits):", self.size());
Comment thread
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) {
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
print!(" +");
} else {
print!(" -");
}
print!(" ");
if i % 2 != 0 {
print!("|");
}
}
println!();

for i in 0..self.size() {
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
print!("QB{} ||", i + 1);
let column = self.pauli_column(i).to_string();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 PauliString. I'd rather construct the string here from the ground up, using e.g. pauli_letter to get the letters in the Pauli string.

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 {
Expand Down
27 changes: 27 additions & 0 deletions src/data_structures/pauli_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ impl PauliPolynomial {
pub fn angle(&self, i: usize) -> Angle {
self.angles.read().unwrap()[i]
}

pub fn visualize_pauli_polynomial(&self) {
println!("Pauli Polynomial size:{} ", self.size());
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
let angles = self.angles.read().unwrap();
let string_angles = angles
.iter()
.map(|x| format!("{:.3}", x)) //force 3 decimal place for easy formatting, is it reasonable?
.collect::<Vec<String>>()
.join(" | ");
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
println!("Angles | {} |", string_angles);
let chains = self.chains();
let mut index = 0;
for chain in chains {
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
print!("Qubit {}|", index);
let chain_str = chain.to_string();
let mut out = String::new();
for ch in chain_str.chars() {
out.push(ch);
if !ch.is_whitespace() {
out.push_str(" |"); //bad, hardcoded spaces. Do we want variable length ?
}
}
println!(" {}", out);
index += 1;
}
} //visualize pauli polynomial is currently a method of the class, The formatting is
//hardcoded so it can be easily broken if input parameter changed.
Comment thread
tungbuidang marked this conversation as resolved.
Outdated
}

impl PropagateClifford for PauliPolynomial {
Expand Down
10 changes: 10 additions & 0 deletions src/ir/pauli_exponential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ impl PauliExponential {
clifford_tableau,
}
}

pub fn visualize_pauli_exponential(&self) {
println!("Visualizing Pauli Exponential:");
// println!("Clifford Tableau:");
self.clifford_tableau.visualize_tableaus();
// println!("Pauli Polynomials:");
for polynomial in &self.pauli_polynomials {
polynomial.visualize_pauli_polynomial();
}
}
}

#[derive(Default)]
Expand Down
Loading