Skip to content

Commit c84e7d5

Browse files
committed
added matrix power
1 parent 397c002 commit c84e7d5

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ pip install git+https://github.com/EQuS/jaxquantum.git
3030

3131
If you are interested in contributing to the package, please clone this repository and install this package in editable mode after changing into the root directory of this repository:
3232
```
33-
pip install -e ".[dev]"
33+
pip install -e ".[dev,docs]"
3434
```
35-
This will also install extras from the `dev` flag, which can be useful when developing the package. Since this is installed in editable mode, the package will automatically be updated after pulling new changes in the repository.
35+
This will also install extras from the `dev` and `docs` flags, which can be useful when developing the package. Since this is installed in editable mode, the package will automatically be updated after pulling new changes in the repository.
3636

3737
### Installing from PyPI (not recommended)
3838

docs/getting_started/installation.md

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
1-
# Installation
1+
## Installation
22

3-
*Conda users, please make sure to `conda install pip` before running any pip installation if you want to install `jaxquantum` into your conda environment.*
43

5-
`jaxquantum` is published on PyPI. So, to install the latest version from PyPI, simply run the following code to install the package:
4+
### Installing from source (recommended)
65

7-
```bash
8-
pip install jaxquantum
6+
**Recommended:** As this is a rapidly evolving project, we recommend installing the latest version of `jaxquantum` from source as follows:
7+
```
8+
pip install git+https://github.com/EQuS/jaxquantum.git
99
```
10-
If you also want to download the dependencies needed to run optional tutorials, please use `pip install jaxquantum[dev,docs]` or `pip install 'jaxquantum[dev,docs]'` (for `zsh` users).
11-
12-
#### Building from source
1310

14-
To build `jaxquantum` from source, pip install using:
11+
### Installing from source in editable mode (recommended for developers)
1512

16-
```bash
17-
git clone git@github.com:EQuS/jaxquantum.git jaxquantum
18-
cd jaxquantum
19-
pip install --upgrade .
13+
If you are interested in contributing to the package, please clone this repository and install this package in editable mode after changing into the root directory of this repository:
2014
```
15+
pip install -e ".[dev,docs]"
16+
```
17+
This will also install extras from the `dev` and `docs` flags, which can be useful when developing the package. Since this is installed in editable mode, the package will automatically be updated after pulling new changes in the repository.
2118

22-
If you also want to download the dependencies needed to run optional tutorials, please use `pip install --upgrade .[dev,docs]` or `pip install --upgrade '.[dev,docs]'` (for `zsh` users).
19+
### Installing from PyPI (not recommended)
2320

24-
#### Installation for Devs
21+
`jaxquantum` is also published on PyPI. Simply run the following code to install the package:
2522

26-
If you intend to contribute to this project, please install `jaxquantum` in editable mode as follows:
2723
```bash
28-
git clone git@github.com:EQuS/jaxquantum.git jaxquantum
29-
cd jaxquantum
30-
pip install -e .[dev, docs]
24+
pip install jaxquantum
3125
```
3226

33-
Please use `pip install -e '.[dev, docs]'` if you are a `zsh` user.
34-
35-
Installing the package in the usual non-editable mode would require a developer to upgrade their pip installation (i.e. run `pip install --upgrade .`) every time they update the package source code.
36-
37-
#### Install with GPU support (Linux)
27+
### Install with GPU support (Linux)
3828

3929
For linux users who wish to enable Nvidia GPU support, here are some steps ([ref](https://jax.readthedocs.io/en/latest/installation.html#nvidia-gpu)):
4030

jaxquantum/core/qarray.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ def __mul__(self, other):
200200
self.data * multiplier,
201201
dims=self._qdims.dims,
202202
)
203+
204+
def __pow__(self, other):
205+
if not isinstance(other, int):
206+
return NotImplemented
207+
208+
return powm(self, other)
203209

204210
def __rmul__(self, other):
205211
return self.__mul__(other)
@@ -247,7 +253,6 @@ def space_dims(self):
247253
else:
248254
raise ValueError("Unsupported qtype.")
249255

250-
251256
@property
252257
def data(self):
253258
return self._data
@@ -320,7 +325,7 @@ def keep_only_diag_elements(self):
320325

321326

322327
# Qarray operations ---------------------------------------------------------------------
323-
328+
324329
def unit(qarr: Qarray) -> Qarray:
325330
"""Normalize the quantum array.
326331
@@ -390,6 +395,18 @@ def expm(qarr: Qarray, **kwargs) -> Qarray:
390395
data = expm_data(qarr.data, **kwargs)
391396
return Qarray.create(data, dims=dims)
392397

398+
def powm(qarr: Qarray, n: int) -> Qarray:
399+
"""Matrix power.
400+
401+
Args:
402+
qarr (Qarray): quantum array
403+
n (int): power
404+
405+
Returns:
406+
matrix power
407+
"""
408+
data = jnp.linalg.matrix_power(qarr.data, n)
409+
return Qarray.create(data, dims=qarr.dims)
393410

394411
def cosm_data(data: Array, **kwargs) -> Array:
395412
"""Matrix cosine wrapper.

0 commit comments

Comments
 (0)