ppvm_vihaco::observable
observable¶
ppvm_vihaco::observable
Parse the `device circuit.observable` header value into Pauli-sum terms.
Lives in `ppvm-vihaco` rather than `ppvm-runtime` because it only parses header syntax that `ppvm-vihaco` consumes; `ppvm-runtime` has no notion of a textual observable. The unrelated `PauliPattern::parse` in `ppvm-runtime` is a matcher grammar (alternation, star, positional anchors) and shares only the `I/X/Y/Z` alphabet with this one.
Grammar (informal): ```text sum = WS* term (WS* sign WS* term)* WS* term = coefficient (WS* '')? WS pauli_word | pauli_word sign = ’+’ | ’-’ coefficient = digits (’.’ digits?)? ([eE] [+-]? digits)? | ’.’ digits ([eE] [+-]? digits)? pauli_word = [IXYZ]{n_qubits} ```
- The first term may have a leading `+` or `-` (no sign means `+`).
- Absent coefficient defaults to `1.0`.
- The `*` is only legal after a coefficient — bare `*ZZ` is rejected.
- The word must be exactly `n_qubits` characters from `I/X/Y/Z`.
Rejected at parse time:
- Empty or whitespace-only input.
- Bare coefficients with no Pauli word.
- Words shorter or longer than `n_qubits`.
- Invalid Pauli characters.
- Missing `+`/`-` between terms.
functionparse_pauli_sum_terms¶source
ppvm_vihaco::observable::parse_pauli_sum_terms
Signature
pub fn parse_pauli_sum_terms(input: &str, n_qubits: usize) -> Result<Vec<(String, f64)>>Parameters
| Name | Type | Description |
|---|---|---|
input | &str | |
n_qubits | usize |
Returns
Result<Vec<(String, f64)>>
Parse a Pauli-sum string like `“1.0ZZ + 0.5XX - 0.3*YY”` into a list of `(word_source, coefficient)` pairs. Callers convert the word source to their preferred Pauli-word type via `PauliWord::from` / `LossyPauliWord::from`.
source