MindQuantum-HiQ / ProjectQ

ProjectQ: An open source software framework for quantum computing
https://projectq.ch
Apache License 2.0
5 stars 2 forks source link

Problem with parameter assignments #1

Open yezhuoyang opened 4 years ago

yezhuoyang commented 4 years ago

I suggest that hiq-projectq should add an interface for changing parameters of a fixed-structure circuit. In some research about quantum machine learning, parameters are changed respect to the gradients in order to minimize the cost function, while the structure of circuit is not changed. In such cases, it is unnecessary for hiq-projectq to re-construct the whole quantum circuit. The parameter might be stored independently.

Takishima commented 4 years ago

Dear @yezhuoyang ,

Could you please elaborate a little more on the exact kind of behaviour you would like to see?

If you could provide a MWE or some pseudo-code showcasing the behaviour you would like to see, that would be most helpful.

yezhuoyang commented 4 years ago

Thanks for your reply and attention @Takishima !
As an example here , in some experiments I want a circuit composed of an Rz gate with parameter x. x may be changed during my experiments but I don' want to create the same circuit again and again.

The original code for x=3 might be written as follows:

  def create_circuit_and_measure() 
       eng = MainEngine()
       qubit=eng.allocate_qureg(1)
       Rz(3) | qubit
      Measure|qubit
      eng.flush()

Perhaps hiq could add a new kind of engine that can accept variables called ParameterEngine and the function goes as:

   eng = ParameterEngine('x')
   qubit=eng.allocate_qureg(1)
   Rz('x') | qubit
   Measure|qubit
   eng.flush('x'=3)
  eng.flush('x'=4)
   eng.flush('x'=5)  

Now, we are able to measure the result with different parameters without reconstructing the same circuits.

Takishima commented 4 years ago

Dear @yezhuoyang ,

We do have an implementation of something similar to what you are proposing in the works. We are just waiting to finish our internal review process and then we will release it on GitHub.

I am unfortunately unable to give you a definitive deadline for the release of that feature though, but it should not be long.