XanaduAI/QMLT

Wrong name for `circuit` parameter in learner.py

Closed this issue · 6 comments

The circuit object in CircuitLearner class is not necessarily a circuit.
Calling it "circuit" works in the simple example, but our real goal is not really optimizing the output from the circuit, but what it represents.
Example: if I want to solve MaxCut problem, I don't really care about the exact values circuit returns, rather what they encode. But in order to do optimize it using QMLT I have to put the encoding/decoding and calculating loss function inside the circuit function.

My proposition would be to change it from circuit to circuit_evaluator, but maybe you have some better ideas.
If you agree and we choose a name I can do a PR.
@josh146 @mariaschuld ?

You are right, it is kind of the result of a variational circuit with potential classical post-processing.

Circuit_evaluator sounds good to me. I also cannot think of a shorter name. If you want, go ahead and refactor.

Thanks!

Thanks!
However, now I've realized, that maybe I should just implement encoding and optimization logic in the loss function and circuit should just return the results of the circuit?
For now my loss returns just circuit_output.

Probably having optimization logic in loss is a good idea, but I still think circuit is not the best name for this parameter.

Yes, the optimization objective goes into the loss function. This gives rise to a bit of an awkward structure where the result of circuit is internally passed to loss, but it has a conceptual clarity and allows one to evaluate the circuit after training.

I interpreted a variational circuit as the quantum circuit + a minor postprocessing of expectations (such as taking a linear combination of them. Hence the name. Still happy to find a better name, so shout if you have one.

Will close this for now, but we can reopen it any time.

One more thing:
I don't think it's possible to get multiple outputs at once using current structure.
One circuit will give me only one result, which I can use only once in the loss function.

However, since my result is probabilistic, I want to get multiple results. Right now I can do that only by putting my whole optimization logic to the circuit.
But I think it should be a QMLT feature, so I can have another hyperparameter, which specifies how many times should I run the circuit. Then loss would be calculated as an average loss for all these instances.

Am I right, and if so, what do you think about adding such parameter?

You are right, the QMLT is designed to have a deterministic output or expectation value as a circuit_output, not measurement results.

I wonder though, you should be able to use probabilistic results. You could write the measurement results in an array that you return as circuit_outputs, and then you work with that array in the loss function.

Or, if one measurement only goes into the loss in each run, you can obviously just return this one...This might result in very crude approximations to the true gradient though.

Since this depends very much on your code, would you like to post an MWE, or send me some code to maria@xanadu.ai?