Cost function in HQNN


I have a query regarding cost function globality and locality which I recently come across in this paper, and are definded below.

Global Cost Function:

Local Cost Function:

My question is how is it applicable in HQNNs (built in pennylane) where a cost function from classical machine learning library (keras) is defined, for instance cross_entropy .

The HQNN working (I have used) is as follows:
input --> Data encoding --> quantum circuit with measurements--> classical neuron layer --> output

How can the cross_entropy cost function be combined with the global and local cost function definitions, defined above?

As per my understanding the global cost function means measure all qubits in an n-qubit system where as local cost function means measuring single qubit in an n-qubit system. In that case the above equations for both global and local cost function are just the representation of all and single qubit measurement respectively, right? I mean just representing the output of quantum circuit?

Any help would be appreciated. Thanks

Hi @Muhammad_Kashif,

We’re looking into your question and will come back soon with an answer!

You got us thinking here :smile:

Hi @CatalinaAlbornoz,

Thanks for the response and looking into my query.
I will eagerly waiting to hear back from you soon.

Thanks again…!

Hi @Muhammad_Kashif,

I dont know too much about hybrid qnns, but the result about barren plateau only concerns the quantum part of your neural network. The cross_entropy in the end does not need to be made local as far as I know.

However, you need to be careful what output measurements you are outputting from the qnn layer. The paper you are citing basically states that
a) the cost function needs to be local, i.e. you need to output measurements of local observerbales (e.g. return [qml.expval(op) for op in local_ops] in your qnode where local_ops are for example Pauli strings acting on few qubits).
b) The QNN needs to be shallow, where shallowness is here defined as the depth being logarithmic in the number of qubits (but this is more a scaling argument, you are most likely looking at a fixed system size?).

Let me know if that helps.

Hi @Korbinian_Kottmann,

Thanks for your input.

Regarding the paper I cited;
Actually my understanding of global and local cost function definitions in equations mentioned in my original post is the same, i.e., local cost function essentially entails measuring single (or few) qubits in a multi-qubit QNN whereas global cost function means measuring all the qubits in the underlying QNN. I actually wanted to confirm if my understanding is correct?

I agree that issue of BP is related to quantum part only. However, in HQNNs there is some classical influence (classical neurons layers) as well, where we can define (classical) cost function and possibly other parameters from classical ML.
In my query, the cost function (cross_entropy) will be governing the optimization rules of HQNN irrespective of global/local measurement of preceding QNN and these global/local cost function of QNNs just represent the output form of QNN which is then processed by the following classical layer in HQNNs, right?

Regarding the depth I am actually trying and experimenting with different widths and depths of quantum layers in HQNNs rather than a fixed size to see how are global and local cost function definitions (in quantum part) play the role.

Any further input would be appreciated. Many thanks.

My understanding is that also in the local cost function you can measure all qubits, its just that each expectation value is a local observable. Take e.g. H_\text{local} = \sum_i X_i as an example of local observable that involves all qubits. In that case you would pass e.g. each individual term <X_i> from your qnn layer to whatever comes after.

Hope that helps!

Hi @Korbinian_Kottmann,

got it… thanks… However, strictly being in the scope of the paper I cited, didn’t the authors mean single qubit measurement in a multi-qubit systems when referring to a local cost function and all-qubit measurement in global cost function.


In the example of a local cost function that you cite above, the observable is a sum over single qubit operators, all acting on different qubits. So it is not a single qubit measurement, but rather a sum over single qubit measurements.

Indeed the notion can be a bit confusing. You are still measuring all qubits. The difference is that in one case a true global observable is measured, whereas in the local case only local observables are measured.

FYI it doesnt even have to be single qubit measurements, it can also be m-body terms, as long as m is relatively small. More details are in the paper around equation (10) and (16).