1
$\begingroup$

I'm using pennylane.

What I want to do is

  1. Create a qnode with the 2*2 density matrix of a single qubit one. It has the parameter as phi
  • Given density matrix: $$\frac{1}{\gamma\cos(\varphi)+(\gamma-2)\mathrm{e}^{\frac{t}{t_2}}}\begin{pmatrix}(\gamma-1)\left(\mathrm{e}^{\frac{t}{t_2}}+\cos(\varphi)\right)&\mathrm{i}\sqrt{1-\gamma}\sin(\varphi)\\-\mathrm{i}\sqrt{1-\gamma}\sin(\varphi)&\cos(\varphi)-\mathrm{e}^{\frac{t}{t_2}}\end{pmatrix}$$
  1. Pass is to qml.qinfo.classical_fisher(). I want to calculate classical fisher information respect to phi.

But the problem is that when I create qnode with density matrix and pass it to qml.qinfo.classical_fisher() it shows the following error:

DeviceError: Gate QubitDensityMatrix not supported on device default.qubit.autograd

Is there any possible method to define a qnode with a custom density matrix available to use with autograd?

I tried to convert it to a state vector but since the density matrix is a mixed state it can't be converted to state vector.

Here is my code:

import pennylane as qml
from pennylane import numpy as np

t1, t2, gamma = 1, 1, 0.5

# Define the density matrix
def rho_ps(phi):
    density_matrix_ps = np.array([
        [(gamma - 1)*(np.exp(t1/t2) + np.cos(phi)), 1.j * np.sqrt(1-gamma)*np.sin(phi)],
        [-1.j * np.sqrt(1-gamma)*np.sin(phi), np.cos(phi) - np.exp(t1/t2)]]) / (gamma*np.cos(phi) + (gamma-2)*np.exp(t1/t2))

    return density_matrix_ps

n_wires = 1
dev = qml.device("default.qubit", wires=n_wires)

# Define the qnode with density matrix
@qml.qnode(dev)
def circ(params):
    density_matrix = rho_ps(params)
    qml.QubitDensityMatrix(density_matrix, wires=0)  # Initialize the qubit with the density matrix

    return qml.expval(qml.PauliZ(0))

# Generate parameters used in classical fisher information
params = np.array([np.pi])
CFIM = qml.qinfo.classical_fisher(circ)

print(CFIM)
```
$\endgroup$

1 Answer 1

1
$\begingroup$

My previous answer mistakenly read quantum_fisher instead of classical_fisher. It is actually possible to compute the latter with mixed states, but not the former.

It seems that there are three problems in your code:

  • The device you use should be default.mixed, since the density matrix you care about is mixed.
  • params should be differentiable, and should thus be created with requires_grad=True
  • CFIM must be called on params, as it's a function

All in all, the following code gives you what you want (If I'm not mistaken):

import pennylane as qml
from pennylane import numpy as np

t1, t2, gamma = 1, 1, 0.5

# Define the density matrix
def rho_ps(phi):
    density_matrix_ps = np.array([
        [(gamma - 1)*(np.exp(t1/t2) + np.cos(phi)), 1.j * np.sqrt(1-gamma)*np.sin(phi)],
        [-1.j * np.sqrt(1-gamma)*np.sin(phi), np.cos(phi) - np.exp(t1/t2)]]) / (gamma*np.cos(phi) + (gamma-2)*np.exp(t1/t2))

    return density_matrix_ps

dev = qml.device("default.mixed", wires=[0])

@qml.qnode(dev)
def circ(params):
    density_matrix = rho_ps(params)
    qml.QubitDensityMatrix(density_matrix, wires=0)

    return qml.expval(qml.PauliZ(0))

params = np.array([np.pi], requires_grad=True)
CFIM = qml.qinfo.transforms.classical_fisher(circ)
print(CFIM(params))
$\endgroup$
4
  • $\begingroup$ Thanks. I posted it on github link $\endgroup$
    – Donguk kim
    Sep 10, 2023 at 10:00
  • $\begingroup$ @Dongukkim I've realized that my previous answer wasn't right for your use case, as you want to use classical_fisher, and not the quantum one. I think it is doable in this case, please see my edited answer $\endgroup$ Sep 10, 2023 at 11:10
  • $\begingroup$ I just changed "defualt.qubit" -> "default.mixed" as you mentioned and it just perfectly works. Thanks for excellent job!!! $\endgroup$
    – Donguk kim
    Sep 11, 2023 at 0:37
  • $\begingroup$ @Dongukkim Glad that helped! $\endgroup$ Sep 11, 2023 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.