Skip to content

Commit 2fe85ba

Browse files
add faq and logo
1 parent 1c83635 commit 2fe85ba

File tree

7 files changed

+70
-2
lines changed

7 files changed

+70
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414

1515
- add `expectation_ps` as shortcut to get Pauli string expectation
1616

17+
- add `append` and `prepend` to compose circuits
18+
1719
### Changed
1820

1921
- change the return information of `unitary_kraus` and `general_kraus` methods
2022

23+
- add alias for any gate as unitary
24+
2125
## 0.0.220328
2226

2327
### Added

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<h1 align="center"> TENSORCIRCUIT </h1>
1+
<p align="center">
2+
<a href="https://pennylane.ai">
3+
<img width=80% src="docs/source/statics/logo.png">
4+
</a>
5+
</p>
26

37
<p align="center">
48
<!-- tests (GitHub actions) -->

docs/source/faq.rst

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Frequently Asked Questions
2+
============================
3+
4+
How can I run TensorCircuit on GPU?
5+
-----------------------------------------
6+
7+
This is done directly through the ML backend. GPU support is totally determined by whether ML libraries are can run on GPU, we don't handle this within tensorcircuit.
8+
It is the users' responsibility to configure an GPU compatible environment for these ML packages. Please refer to the installation documentation for these ML packages and directly use official dockerfiles provided by TensorCircuit.
9+
With GPU compatible enviroment, we can switch the use of GPU or CPU by a backend agnostic environment variable ``CUDA_VISIBLE_DEVICES``.
10+
11+
What is the counterpart of ``QuantumLayer`` for PyTorch and Jax backend?
12+
----------------------------------------------------------------------------
13+
14+
Since PyTorch doesn't have mature vmap and jit support and Jax doesn't have native classical ML layers, we highly recommend TensorFlow as the backend for quantum-classical hybrid machine learning tasks, where ``QuantumLayer`` plays an important role.
15+
For PyTorch, we can in pricinple wrap the corresponding quantum function into a PyTorch module, but we currently has no built-in support for this wrapper.
16+
In terms of Jax backend, we highly suggested to keep the functional programming paradigm for such machine learning task.
17+
Besides, it is worthing noting that, jit and vmap is automatically taken care of in ``QuantumLayer``.
18+
19+
20+
Is there some API less cumbersome than ``expectation`` for Pauli string?
21+
----------------------------------------------------------------------------
22+
23+
Say we want to measure something like :math:`\langle X_0Z_1Y_2Z_4 \rangle` for a six-qubit system, the general ``expectation`` API may seems to be cumbersome.
24+
So one can try one of the following options:
25+
26+
* ``c.expectation_ps(x=[0], y=[2], z=[1, 4])``
27+
28+
* ``tc.templates.measurements.parameterized_measurements(c, np.array([1, 3, 2, 0, 3, 0]), onehot=True)``
29+
30+
Can I apply quantum operation based on previous classical measurement result in TensorCircuit?
31+
----------------------------------------------------------------------------------------------------
32+
33+
Try the following: (the pipeline is even fully jittable!)
34+
35+
.. code-block:: python
36+
37+
c = tc.Circuit(2)
38+
c.H(0)
39+
r = c.cond_measurement(0)
40+
c.conditional_gate(r, [tc.gates.i(), tc.gates.x()], 1)
41+
42+
``cond_measurement`` will return 0 or 1 based on the measurement result on z-basis, and ``conditional_gate`` applies gate_list[r] on the circuit.

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Guide to TensorCircuit
66

77
quickstart.rst
88
advance.rst
9+
faq.rst
910
infras.rst
1011
contribution.rst
1112
tutorials.rst

docs/source/index_cn.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Guide to TensorCircuit
66

77
quickstart.rst
88
advance.rst
9+
faq.rst
910
infras.rst
1011
contribution.rst
1112
tutorials_cn.rst

docs/source/statics/logo.png

248 KB
Loading

tensorcircuit/circuit.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ class Circuit:
5959
]
6060
mpogates = ["multicontrol", "mpo"]
6161

62-
gate_alias_list = [["cnot", "cx"], ["fredkin", "cswap"], ["toffoli", "ccnot"]]
62+
gate_alias_list = [
63+
["cnot", "cx"],
64+
["fredkin", "cswap"],
65+
["toffoli", "ccnot"],
66+
["any", "unitary"],
67+
]
6368

6469
def __init__(
6570
self,
@@ -751,6 +756,17 @@ def cond_measurement(self, index: int) -> Tensor:
751756

752757
cond_measure = cond_measurement
753758

759+
def prepend(self, c: "Circuit") -> "Circuit":
760+
self.replace_mps_inputs(c.quvector())
761+
self._qir = c._qir + self._qir
762+
return self
763+
764+
def append(self, c: "Circuit") -> "Circuit":
765+
c.replace_mps_inputs(self.quvector())
766+
c._qir = self._qir + c._qir
767+
self.__dict__ = c.__dict__
768+
return self
769+
754770
def depolarizing2(
755771
self,
756772
index: int,

0 commit comments

Comments
 (0)