|
| 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. |
0 commit comments