Outputs of the VQCs

Hello, what are the outputs of current variational quantum circuits? Is it possible to directly output a vector similar to the input, or must the output be obtained through measurement?

Hi @zj-lucky,

The output must be obtained through measurement. You can indeed output a vector, for example the expectation value for each of the qubits. You must then use a cost function which has a single scalar as the output, so that you can use PennyLane’s standard optimization methods.

Feel free to check out the examples in some of our QML demos to see how to do this. We also have a new Codebook Module on Variational Quantum Algorithms, which you might like.

I hope this helps!

Thank you very much!

I have another problem which needs your help.
Here is the issue we are encountering with our quantum circuit:

@qml.qnode(dev, interface="torch", diff_method="backprop")
def qcnn_circuit(inputs, params):

    qml.QubitStateVector(inputs, wires=range(num_qubits))

    U_block(params, wires=range(num_qubits))

    return qml.probs(wires=range(num_qubits))

When the num_qubits is set to 16, the following error occurs due to cache limitations:

raceback (most recent call last):
  File "/home/zj/ARPES/QCNN_V1.py", line 320, in <module>
    output_probs = model(low_tensor)
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/zj/ARPES/QCNN_V1.py", line 247, in forward
    return qcnn_circuit(inputs, self.params)
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/pennylane/qnode.py", line 889, in __call__
    res = qml.execute(
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/pennylane/interfaces/execution.py", line 656, in execute
    qml.interfaces.cache_execute(
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/pennylane/interfaces/execution.py", line 222, in wrapper
    cache[hashes[i]] = r
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/cachetools/__init__.py", line 217, in __setitem__
    cache_setitem(self, key, value)
  File "/home/zj/anaconda3/envs/py38/lib/python3.8/site-packages/cachetools/__init__.py", line 76, in __setitem__
    raise ValueError("value too large")
ValueError: value too large

We need a solution to address this issue without compromising the structure of the circuit or its output. Specifically, the qml.probs(wires=range(num_qubits)) measurement with 16 qubits is essential for our application.

@CatalinaAlbornoz

Thank you very much, pls see above problem.

Hi @zj-lucky,

I’m not sure if this will solve the issue but if possible I’d suggest upgrading your Python version. Our minimum supported version at the moment is Python 3.10.

Let me know if this solves your issue.

@CatalinaAlbornoz Thank you very much. This problem has been solved following your suggestion.

That’s great to hear @zj-lucky !