Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Noisy VQE in Qulacs #302

Open
StefanoBarison opened this issue Jan 26, 2022 · 3 comments
Open

Noisy VQE in Qulacs #302

StefanoBarison opened this issue Jan 26, 2022 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@StefanoBarison
Copy link

Good morning,

I was trying to use Qulacs for a simple VQE on the Ising chain Hamiltonian.
I followed the tutorial and everything works fine until I put DepolarizingNoise as gates in the circuit.
The scipy.optimize.minimize method seems to have problem with noisy cost functions, sometime the calculation ends, other time it gets stuck at the first iteration, so it's very inconsistent.

Is there a specific way to do noisy VQE calculation in Qulacs?

Thanks

@corryvrequan
Copy link
Contributor

corryvrequan commented Jan 28, 2022

As far as I have heard and tested, qulacs's simulation works also for noisy circuits.

I'm sorry if my guess is wrong. I guess the scipy-optimize stops at the first iteration since you execute the circuit simulation with state vector. In other words, if you use the QuantumState class to create a quantum state, the problem may be resolved by replacing it with DensityMatrix as state = DensityMatrix(n_qubit) with from qulacs import DensityMatrix.

In qulacs, there are two classes that represent the quantum state: StateVector (this class is the same as QuantumState) and DensityMatrix.
When a noisy gate such as DepolarizingNoise is applied to StateVector, a pure state is sampled from the resultant density matrix. More concretely saying, any of |psi>, X |psi>, Y|psi>, Z|psi> is sampled randomly. On the other hand, a noisy gate maps a DensityMatrix object to another DensityMatrix object deterministically.

In the tutorial's example, a quantum state is simulated only once per iteration. Thus, if you use StateVector for your simulation, the expectation values will differ even if you feed the same rotation angles since the behavior of noisy gates are random. Since scipy-optimize expects that a given cost function outputs the same value for the same parameters, scipy-optimize stops immediately if the cost function returns different values for the same parameters.

Thus, there are two ways to resolve them.

  1. Use DensityMatrix instead of QuantumState.
  2. Modify the cost function so that it repeats initialization, circuit simulation, and sampling (or calculation of expectation values) and returns their average as costs.

As far as I checked, the example in the tutorial does not work when we add noisy quantum gates to the circuits, but it works again when I replace QuantumState with DensityMatrix. Note that the simulation with DensityMatrix takes a longer time than the state vector simulation.

@StefanoBarison
Copy link
Author

@corryvrequan thanks a lot for the answer and sorry for the late reply.

I indeed tested the tutorial with DensityMatrix and it works with consistent results. Thank you

In this regards, I would like to add another question:
what is the correct way to define a noisy circuit in Qulacs? If I want to have a depolarising noise associated to everyy single qubit operation is sufficient to add a DepolarizingNoise gate after every one of them? Then I think for 2-qubits gates I will have to consider TwoQubitDepolarizingNoise,right?

Many thanks again,
Stefano

@ikanago ikanago added the help wanted Extra attention is needed label Mar 14, 2024
@forest1040
Copy link
Contributor

@StefanoBarison
YES.
If you only need Depolarizing Noise, I think you can do that.
Creating a noise model is easier with QURI-Parts.
https://github.com/QunaSys/quri-parts
https://quri-parts.qunasys.com/tutorials/noise_error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants