Metadata-Version: 2.4
Name: second_quantization
Version: 0.1.0
Summary: Converting second quantized operators to matrix form and back
Project-URL: Documentation, https://qt.pages.quantumtinkerer.group/second_quantization/index.html
Project-URL: Repository, https://gitlab.kwant-project.org/qt/second_quantization
Project-URL: Bug Tracker, https://gitlab.kwant-project.org/qt/second_quantization/-/issues
Author: Quantum Tinkerers
License: BSD 2-Clause License
        
        Copyright (c) 2024, MeanFi authors
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: AUTHORS.md
License-File: LICENSE
Keywords: linear algebra,operators,quantum,second quantization
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Requires-Dist: numpy>=2.0
Requires-Dist: packaging>=22.0
Requires-Dist: scipy>=1.8
Requires-Dist: sympy>=1.13
Provides-Extra: docs
Requires-Dist: markdown>=3.6; extra == 'docs'
Requires-Dist: mkdocs-bibtex>=4.4; extra == 'docs'
Requires-Dist: mkdocs-material>=9.6; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings-python>=1.8; extra == 'docs'
Requires-Dist: mkdocstrings>=0.30; extra == 'docs'
Requires-Dist: pymdown-extensions>=10.14; extra == 'docs'
Provides-Extra: test
Requires-Dist: pytest-cov>=6; extra == 'test'
Requires-Dist: pytest-randomly>=3.15; extra == 'test'
Requires-Dist: pytest-regressions; extra == 'test'
Requires-Dist: pytest-repeat>=0.9; extra == 'test'
Requires-Dist: pytest>=8.3; extra == 'test'
Requires-Dist: ruff>=0.9; extra == 'test'
Description-Content-Type: text/markdown

# Second Quantization

[![PyPI version](https://badge.fury.io/py/second-quantization.svg)](https://badge.fury.io/py/second-quantization)
[![Tests](https://gitlab.kwant-project.org/qt/second_quantization/badges/main/pipeline.svg)](https://gitlab.kwant-project.org/qt/second_quantization/-/pipelines)

A Python package for seamless conversion between symbolic second-quantized operators and their numerical matrix representations.

## Features

- **Symbolic to Matrix**: Convert fermionic operators (creation/annihilation) to matrix form using Jordan-Wigner transformation
- **Matrix to Symbolic**: Decompose matrices back into fermionic operator expressions
- **Efficient**: Supports both dense and sparse matrix representations for large Hilbert spaces
- **Flexible**: Handle parameterized Hamiltonians with symbolic coefficients
- **Fast Parameter Sweeps**: Reuse basis operators for different parameter values

## Installation

```bash
pip install second-quantization
```

## Quick Start

```python
import sympy
from sympy.physics.quantum.fermion import FermionOp
from sympy.physics.quantum import Dagger
from second_quantization import hilbert_space

# Define fermionic operators
c, d = [FermionOp(name) for name in "cd"]

# Create a simple Hamiltonian: t(c†d + d†c) + U c†c d†d
t, U = sympy.symbols("t U", real=True)
H = t * (Dagger(c) * d + Dagger(d) * c) + U * Dagger(c) * c * Dagger(d) * d

# Convert to matrix representation
matrix_dict = hilbert_space.to_matrix(H, operators=[c, d], sparse=False)

# Create a callable function for parameter sweeps
hamiltonian_func = hilbert_space.make_dict_callable(matrix_dict)

# Generate Hamiltonian for specific parameter values
H_matrix = hamiltonian_func(t=1.0, U=2.5)
```

## Documentation

Full documentation with tutorials and API reference is available at:
[https://qt.pages.quantumtinkerer.group/second_quantization/](https://qt.pages.quantumtinkerer.group/second_quantization/)

## Use Cases

- **Quantum Many-Body Physics**: Study interacting fermion systems
- **Quantum Chemistry**: Molecular Hamiltonians and electronic structure
- **Condensed Matter**: Hubbard models, topological systems, quantum dots
- **Quantum Computing**: Variational quantum algorithms, QAOA
- **Education**: Learn fermionic second quantization interactively

## Core Functions

### `hilbert_space.to_matrix()`
Convert symbolic fermionic expressions to matrix form using Jordan-Wigner transformation.

### `hilbert_space.make_dict_callable()`
Create efficient callable functions from symbolic Hamiltonians for parameter sweeps.

### `hilbert_space.to_operators()`
Decompose matrices back into symbolic fermionic operator expressions.

### `hilbert_space.basis_operators()`
Generate basis for fermionic Hilbert spaces.

## Requirements

- Python ≥ 3.11
- NumPy ≥ 2.0
- SciPy ≥ 1.8
- SymPy ≥ 1.13

## Contributing

Contributions are welcome! Please see our [repository](https://gitlab.kwant-project.org/qt/second_quantization) for development setup and contribution guidelines.

## License

BSD 3-Clause License. See [LICENSE](LICENSE) for details.
