Skip to content

Commit b4f169f

Browse files
authored
Merge branch 'main' into pulse
2 parents e9d4879 + d5ba80b commit b4f169f

File tree

230 files changed

+89183
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+89183
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ __pycache__/
1010
.Python
1111
build/
1212
develop-eggs/
13+
local_docs/
1314
dist/
1415
downloads/
1516
eggs/

.readthedocs.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
formats:
9+
- pdf
10+
11+
# Set the version of Python and other tools you might need
12+
build:
13+
os: ubuntu-24.04
14+
tools:
15+
python: "3.11"
16+
17+
# Build documentation in the docs/ directory with Sphinx
18+
sphinx:
19+
configuration: docs/source/conf.py
20+
# We recommend specifying your dependencies to enable reproducible builds:
21+
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
22+
python:
23+
install:
24+
- requirements: requirements/requirements-rtd.txt

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on Keep a Changelog (https://keepachangelog.com/en/1.1.0/),
5+
and this project adheres to Semantic Versioning (https://semver.org/spec/v2.0.0.html).
6+
7+
## [0.2.1] - 2025-08-08
8+
### Added
9+
- MCP service integration and multi-tool invocation support in the Homebrew_S2 HTTP API.
10+
11+
### Changed
12+
- Declared official Python support: 3.10+ (tested on 3.10–3.12).
13+
- Docs: Updated localized READMEs (Chinese and Japanese).
14+
- Minor docs typos
15+
16+
## [0.1.1] - 2025-07-21
17+
### Added
18+
- Real quantum hardware (Homebrew_S2) execution path and quantum task management system
19+
- Example `examples/simple_demo_1.py`
20+
### Changed
21+
- Docs: README hardware setup guidance
22+
### Fixed
23+
- Minor docs typos
24+
25+
## [0.1.0] - 2025-01
26+
### Added
27+
- Initial preview release: circuit, compiler, backends, autodiff

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<h3><p align="center">Full-stack Quantum Software Framework on Real Machine</p></h3>
33

44
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5-
[![Python](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
5+
[![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/downloads/)
6+
67
[![Real Quantum Hardware](https://img.shields.io/badge/Quantum%20Hardware-Homebrew__S2-brightgreen)](https://www.tyxonq.com/)
78

89
For Chinese Introduction, see: [中文README](README_cn.md).
@@ -273,8 +274,8 @@ print(g(theta))
273274
```
274275
275276
## Dependencies
276-
- Python >= 3.7 (supports Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12+)
277-
- PyTorch >= 1.8.0
277+
- Python >= 3.10, <3.13 (supports Python 3.10, 3.11, 3.12)
278+
278279

279280
## 📧 Contact & Support
280281

@@ -303,6 +304,14 @@ print(g(theta))
303304
- **Community Contributors**: Open source development and testing
304305

305306

307+
## Changelog
308+
309+
- See the full changelog:[`CHANGELOG.md`](./CHANGELOG.md)
310+
311+
### Recent Updates(Summary)
312+
- v0.2.1 — Official Python 3.10+ support; updated Chinese and Japanese READMEs; Homebrew_S2 HTTP API and documentation updated for multi-tool invocation and MCP service integration.
313+
- v0.1.1 — Initial public release; support for real quantum hardware Homebrew_S2 integration; added cloud task management examples; improved multi-backend and automatic differentiation experience.
314+
- v0.1.0 — Internal preview; framework skeleton with basic circuit/compiler/backend modules.
306315

307316
## License
308317
TyxonQ is open source, released under the Apache License, Version 2.0.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SPHINXPROJ = tensorcircuit
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/ext/toctree_filter.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
sphinx extension for conditional toc
3+
"""
4+
5+
import re
6+
from sphinx.directives.other import TocTree
7+
8+
# adpoted from https://stackoverflow.com/a/46600038
9+
10+
11+
def setup(app):
12+
app.add_directive("toctree-filt", TocTreeFilt)
13+
return {"version": "1.0.0"}
14+
15+
16+
class TocTreeFilt(TocTree):
17+
"""
18+
Directive to notify Sphinx about the hierarchical structure of the docs,
19+
and to include a table-of-contents like tree in the current document. This
20+
version filters the entries based on a list of prefixes. We simply filter
21+
the content of the directive and call the super's version of run. The
22+
list of exclusions is stored in the **toc_filter_exclusion** list. Any
23+
table of content entry prefixed by one of these strings will be excluded.
24+
If `toc_filter_exclusion=['secret','draft']` then all toc entries of the
25+
form `:secret:ultra-api` or `:draft:new-features` will be excuded from
26+
the final table of contents. Entries without a prefix are always included.
27+
"""
28+
29+
hasPat = re.compile("^\s*:(.+):(.+)$")
30+
31+
# Remove any entries in the content that we dont want and strip
32+
# out any filter prefixes that we want but obviously don't want the
33+
# prefix to mess up the file name.
34+
def filter_entries(self, entries):
35+
excl = [self.state.document.settings.env.config.language]
36+
filtered = []
37+
for e in entries:
38+
m = self.hasPat.match(e)
39+
if m != None:
40+
if not m.groups()[0] in excl:
41+
filtered.append(m.groups()[1])
42+
else:
43+
filtered.append(e)
44+
return filtered
45+
46+
def run(self):
47+
# Remove all TOC entries that should not be on display
48+
self.content = self.filter_entries(self.content)
49+
return super().run()

docs/source/advance.rst

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
================
2+
Advanced Usage
3+
================
4+
5+
MPS Simulator
6+
----------------
7+
8+
(Still experimental support)
9+
10+
Very simple, we provide the same set of API for ``MPSCircuit`` as ``Circuit``,
11+
the only new line is to set the bond dimension for the new simulator.
12+
13+
.. code-block:: python
14+
15+
c = tc.MPSCircuit(n)
16+
c.set_split_rules({"max_singular_values": 50})
17+
18+
The larger bond dimension we set, the better approximation ratio (of course the more computational cost we pay)
19+
20+
Split Two-qubit Gates
21+
-------------------------
22+
23+
The two-qubit gates applied on the circuit can be decomposed via SVD, which may further improve the optimality of the contraction pathfinding.
24+
25+
`split` configuration can be set at circuit-level or gate-level.
26+
27+
.. code-block:: python
28+
29+
split_conf = {
30+
"max_singular_values": 2, # how many singular values are kept
31+
"fixed_choice": 1, # 1 for normal one, 2 for swapped one
32+
}
33+
34+
c = tc.Circuit(nwires, split=split_conf)
35+
36+
# or
37+
38+
c.exp1(
39+
i,
40+
(i + 1) % nwires,
41+
theta=paramc[2 * j, i],
42+
unitary=tc.gates._zz_matrix,
43+
split=split_conf
44+
)
45+
46+
Note ``max_singular_values`` must be specified to make the whole procedure static and thus jittable.
47+
48+
49+
Jitted Function Save/Load
50+
-----------------------------
51+
52+
To reuse the jitted function, we can save it on the disk via support from the TensorFlow `SavedModel <https://www.tensorflow.org/guide/saved_model>`_. That is to say, only jitted quantum function on the TensorFlow backend can be saved on the disk.
53+
54+
For the JAX-backend quantum function, one can first transform them into the tf-backend function via JAX experimental support: `jax2tf <https://github.com/google/jax/tree/main/jax/experimental/jax2tf>`_.
55+
56+
We wrap the tf-backend `SavedModel` as very easy-to-use function :py:meth:`tensorcircuit.keras.save_func` and :py:meth:`tensorcircuit.keras.load_func`.
57+
58+
Parameterized Measurements
59+
-----------------------------
60+
61+
For plain measurements API on a ``tc.Circuit``, eg. `c = tc.Circuit(n=3)`, if we want to evaluate the expectation :math:`<Z_1Z_2>`, we need to call the API as ``c.expectation((tc.gates.z(), [1]), (tc.gates.z(), [2]))``.
62+
63+
In some cases, we may want to tell the software what to measure but in a tensor fashion. For example, if we want to get the above expectation, we can use the following API: :py:meth:`tensorcircuit.templates.measurements.parameterized_measurements`.
64+
65+
.. code-block:: python
66+
67+
c = tc.Circuit(3)
68+
z1z2 = tc.templates.measurements.parameterized_measurements(c, tc.array_to_tensor([0, 3, 3, 0]), onehot=True) # 1
69+
70+
This API corresponds to measure :math:`I_0Z_1Z_2I_3` where 0, 1, 2, 3 are for local I, X, Y, and Z operators respectively.
71+
72+
Sparse Matrix
73+
----------------
74+
75+
We support COO format sparse matrix as most backends only support this format, and some common backend methods for sparse matrices are listed below:
76+
77+
.. code-block:: python
78+
79+
def sparse_test():
80+
m = tc.backend.coo_sparse_matrix(indices=np.array([[0, 1],[1, 0]]), values=np.array([1.0, 1.0]), shape=[2, 2])
81+
n = tc.backend.convert_to_tensor(np.array([[1.0], [0.0]]))
82+
print("is sparse: ", tc.backend.is_sparse(m), tc.backend.is_sparse(n))
83+
print("sparse matmul: ", tc.backend.sparse_dense_matmul(m, n))
84+
85+
for K in ["tensorflow", "jax", "numpy"]:
86+
with tc.runtime_backend(K):
87+
print("using backend: ", K)
88+
sparse_test()
89+
90+
The sparse matrix is specifically useful to evaluate Hamiltonian expectation on the circuit, where sparse matrix representation has a good tradeoff between space and time.
91+
Please refer to :py:meth:`tensorcircuit.templates.measurements.sparse_expectation` for more detail.
92+
93+
For different representations to evaluate Hamiltonian expectation in tensorcircuit, please refer to :doc:`tutorials/tfim_vqe_diffreph`.
94+
95+
Randoms, Jit, Backend Agnostic, and Their Interplay
96+
--------------------------------------------------------
97+
98+
.. code-block:: python
99+
100+
import tensorcircuit as tc
101+
K = tc.set_backend("tensorflow")
102+
K.set_random_state(42)
103+
104+
@K.jit
105+
def r():
106+
return K.implicit_randn()
107+
108+
print(r(), r()) # different, correct
109+
110+
.. code-block:: python
111+
112+
import tensorcircuit as tc
113+
K = tc.set_backend("jax")
114+
K.set_random_state(42)
115+
116+
@K.jit
117+
def r():
118+
return K.implicit_randn()
119+
120+
print(r(), r()) # the same, wrong
121+
122+
123+
.. code-block:: python
124+
125+
import tensorcircuit as tc
126+
import jax
127+
K = tc.set_backend("jax")
128+
key = K.set_random_state(42)
129+
130+
@K.jit
131+
def r(key):
132+
K.set_random_state(key)
133+
return K.implicit_randn()
134+
135+
key1, key2 = K.random_split(key)
136+
137+
print(r(key1), r(key2)) # different, correct
138+
139+
Therefore, a unified jittable random infrastructure with backend agnostic can be formulated as
140+
141+
.. code-block:: python
142+
143+
import tensorcircuit as tc
144+
import jax
145+
K = tc.set_backend("tensorflow")
146+
147+
def ba_key(key):
148+
if tc.backend.name == "tensorflow":
149+
return None
150+
if tc.backend.name == "jax":
151+
return jax.random.PRNGKey(key)
152+
raise ValueError("unsupported backend %s"%tc.backend.name)
153+
154+
155+
@K.jit
156+
def r(key=None):
157+
if key is not None:
158+
K.set_random_state(key)
159+
return K.implicit_randn()
160+
161+
key = ba_key(42)
162+
163+
key1, key2 = K.random_split(key)
164+
165+
print(r(key1), r(key2))
166+
167+
And a more neat approach to achieve this is as follows:
168+
169+
.. code-block:: python
170+
171+
key = K.get_random_state(42)
172+
173+
@K.jit
174+
def r(key):
175+
K.set_random_state(key)
176+
return K.implicit_randn()
177+
178+
key1, key2 = K.random_split(key)
179+
180+
print(r(key1), r(key2))
181+
182+
It is worth noting that since ``Circuit.unitary_kraus`` and ``Circuit.general_kraus`` call ``implicit_rand*`` API, the correct usage of these APIs is the same as above.
183+
184+
One may wonder why random numbers are dealt in such a complicated way, please refer to the `Jax design note <https://github.com/google/jax/blob/main/docs/design_notes/prng.md>`_ for some hints.
185+
186+
If vmap is also involved apart from jit, I currently find no way to maintain the backend agnosticity as TensorFlow seems to have no support of vmap over random keys (ping me on GitHub if you think you have a way to do this). I strongly recommend the users using Jax backend in the vmap+random setup.

docs/source/api/about.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tensorcircuit.about
2+
================================================================================
3+
.. automodule:: tensorcircuit.about
4+
:members:
5+
:undoc-members:
6+
:show-inheritance:
7+
:inherited-members:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tensorcircuit.abstractcircuit
2+
================================================================================
3+
.. automodule:: tensorcircuit.abstractcircuit
4+
:members:
5+
:undoc-members:
6+
:show-inheritance:
7+
:inherited-members:

docs/source/api/applications.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
tensorcircuit.applications
2+
================================================================================
3+
.. toctree::
4+
applications/ai.rst
5+
applications/dqas.rst
6+
applications/finance.rst
7+
applications/graphdata.rst
8+
applications/layers.rst
9+
applications/optimization.rst
10+
applications/physics.rst
11+
applications/utils.rst
12+
applications/vags.rst
13+
applications/van.rst
14+
applications/vqes.rst

0 commit comments

Comments
 (0)