Open Pingal-Pratyush-Nath opened 3 months ago
Thanks for pointing this out @Pingal-Pratyush-Nath, this is an interesting and tricky problem! Currently, EstimatorQNN
only supports dynamic parameters but not a feature map with a fully dynamic circuit structure. In my view, this would be achieved in the following way.
Change the EstimatorQNN
arguments to take a (constant) ansatz: QuantumCircuit
and a variable feature_map: QuantumCircuit | Callable[[Any], QuantumCircuit]
similar to QNNCircuit
.
Note that changing the structure of the circuit for every data point (or GraphState
) means that you have to transpile the composed circuit every time, if you want to run on real or emulated hardware, for two reasons (i) to optimise gates and pulses and (ii) to convert the circuit to the backend’s (Instruction Set Architecture (ISA))[https://www.ibm.com/quantum/blog/isa-circuits]. Potentially, this is an expensive operation to repeat every time, so you may want to keep an eye on this step if you're after performance/speed.
Currently, we do not have a plan for including dynamic feature maps in EstimatorQNN
, however, I warmly encourage you to share your ideas and code snippets in this threads so that us and the rest of the community can make suggestions.
What should we add?
The circuit that we pass in the estimator QNN contains two parts : the encoding part(non trainable) and the trainable part. If the encoding circuit changes for every data point, we will have to reinstantiate the model every-time. It would have been better if we can change that encoding part of the model every time we call the model. I know we can create a parameterized circuit and pass in the parameters everytime, but sometimes the circuit itself changes depending on the data point and it is difficult to use Torch Connector for that.
I have added a sample code.