Metadata-Version: 2.4
Name: paulimer
Version: 0.2.10
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Dist: binar>=0.1.7,<0.2
Requires-Dist: pytest>=7.0 ; extra == 'dev'
Requires-Dist: hypothesis>=6.0 ; extra == 'dev'
Requires-Dist: more-itertools>=9.0 ; extra == 'dev'
Requires-Dist: numpy>=1.20 ; extra == 'dev'
Requires-Dist: mypy>=1.0 ; extra == 'dev'
Provides-Extra: dev
Summary: Pauli and Clifford algebra for quantum computing
Keywords: quantum,pauli,clifford,stabilizer,quantum computing,error correction
Author: Microsoft Corporation
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Bug Tracker, https://github.com/microsoft/qdk-ec/issues
Project-URL: Homepage, https://github.com/microsoft/qdk-ec
Project-URL: Repository, https://github.com/microsoft/qdk-ec

# paulimer - Paulis, Cliffords and stabilizer simulation

High-performance Pauli operators, Clifford unitaries, and stabilizer simulation for quantum computing.

## Installation

```bash
pip install paulimer
```

## Quick Start

```python
import paulimer

# Pauli operators
p = paulimer.DensePauli("XYZ")
q = paulimer.SparsePauli("X0 Z100")
print(q * q)  # Identity

# Clifford gates
h = paulimer.CliffordUnitary.from_name("Hadamard", [0], qubit_count=1)
print(h.image_of(paulimer.DensePauli("X")))  # Z

# Decompose a Clifford into pi/4 Pauli exponents (Clifford transvections)
cnot = paulimer.CliffordUnitary.from_name("ControlledX", [0, 1], qubit_count=2)
factors, correction = cnot.to_transvections_minimal()
rebuilt = paulimer.CliffordUnitary.identity(2)
for pauli in factors:
    rebuilt.left_mul_pauli_exp(pauli)
rebuilt.left_mul_pauli(correction)
assert rebuilt == cnot

# Stabilizer simulation
sim = paulimer.OutcomeCompleteSimulation(2)
sim.apply_unitary(paulimer.UnitaryOpcode.Hadamard, [0])
sim.apply_unitary(paulimer.UnitaryOpcode.ControlledX, [0, 1])
sim.measure(paulimer.SparsePauli("Z0"))
```

The minimal API returns the fewest rotations for the unsigned action and a final Pauli for all tableau signs.
The minimum excludes that Pauli. The greedy `to_transvections()` API still returns only an unsigned list.
Neither API reconstructs global phase because the input tableau does not record it.

### Verifying parameterised circuits with symbolic angles

`PhasedOutcomeCompleteSimulation` tracks the exact global phase, so two circuits that share the same
free rotation angles can be checked for exact equality — even for exponents of higher-weight Paulis:

```python
from paulimer import PhasedOutcomeCompleteSimulation, SparsePauli, UnitaryOpcode


def prepared_action(build):
    sim = PhasedOutcomeCompleteSimulation(2)
    for qubit in range(2):
        sim.apply_unitary(UnitaryOpcode.Hadamard, [qubit])  # |++>
    build(sim)
    return sim.phased_action([], [0, 1])  # state-preparation action


def direct(sim):  # e^{i alpha Z0 Z1} |++>
    alpha = sim.allocate_symbolic_angle()
    sim.apply_symbolic_pauli_exp(SparsePauli("Z_0 Z_1"), alpha)


def conjugated(sim):  # CNOT . e^{i alpha Z1} . CNOT |++>
    sim.apply_unitary(UnitaryOpcode.ControlledX, [0, 1])
    alpha = sim.allocate_symbolic_angle()
    sim.apply_symbolic_pauli_exp(SparsePauli("Z_1"), alpha)
    sim.apply_unitary(UnitaryOpcode.ControlledX, [0, 1])


assert prepared_action(direct).is_equivalent(prepared_action(conjugated))
```

`is_equivalent` compares two circuits up to a common global phase. To also compare the global phase,
and so tell operators such as `Co` and `-Co` apart, use
`PhasedCircuitAction.is_equivalent_with_global_phase(other)`. You can also read the `zeta8` exponent
from the `global_phase` property. That exponent is a reference point, not an absolute property of the
operator. It is fixed by the canonical marginal-encoder convention and by the state a discarded
auxiliary qubit is left in, so the identity circuit gives `2` and not `0`. Differences between two
values are meaningful when both actions are built the same way. The property uses the §4.3
auxiliary-qubit separation of arXiv:2603.24717 to recover the encoder's phase.

### Decomposing a Clifford into pi/4 Pauli exponents

`CliffordUnitary.to_pauli_exponents()` returns an ordered product of `pi/4` Pauli exponents that
reproduces the Clifford exactly, including the Pauli-image signs — so replaying it with exact phase
tracking yields a well-defined global phase:

```python
from paulimer import CliffordUnitary, UnitaryOpcode

clifford = CliffordUnitary.identity(2)
clifford.left_mul(UnitaryOpcode.Hadamard, [0])
clifford.left_mul(UnitaryOpcode.ControlledX, [0, 1])

exponents = clifford.to_pauli_exponents()  # list[SparsePauli], each factor exp(+-i pi/4 P)

rebuilt = CliffordUnitary.identity(2)
for pauli in exponents:
    rebuilt.left_mul_pauli_exp(pauli)
assert rebuilt == clifford
```

## Features

- **DensePauli / SparsePauli** - Pauli operators with phase tracking and multiplication
- **CliffordUnitary** - Clifford gates with conjugation, composition, and decomposition into `π/4`
  Pauli exponents (`to_pauli_exponents`, `to_transvections`, `to_transvections_minimal`)
- **PauliGroup** - Group operations including membership testing and factorization
- **Stabilizer Simulation** - Noiseless (OutcomeComplete, OutcomeFree, OutcomeSpecific) and noisy (Faulty) modes
- **PhasedOutcomeCompleteSimulation** - Outcome-complete simulation that additionally tracks the exact global phase, enabling exact equality checking of parameterised (symbolic-angle) circuits

## Use Cases

Designed for quantum error correction research, including stabilizer circuit analysis and Clifford circuit verification. `PhasedOutcomeCompleteSimulation` extends this to exact verification of non-stabilizer circuits built from symbolic Pauli rotations `e^{i alpha P}`.

## Performance

Built on `binar` for SIMD-accelerated binary linear algebra. 

## API Reference

See [paulimer.pyi](paulimer.pyi) for complete type hints and documentation.

## License

MIT License - See LICENSE file for details.

## Contributing

Contributions welcome! See [github.com/microsoft/qdk-ec](https://github.com/microsoft/qdk-ec) for guidelines.

