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

[QIM-6] classical fisher information matrix (as a transform) #2640

Merged
merged 324 commits into from
Jun 10, 2022

Conversation

Qottmann
Copy link
Contributor

Context:
Would be nice to add the classical fisher information matrix (CFIM) eq. (14-15) in 2103.15191.

image

There are some design questions that we should address first though.

The idea is to have it as a transform such that it can be used in a similar fashion as qml.metric_tensor(), i.e. qml.classical_fisher(qnode)(params) outputs the (num_params, num_params) CFIM at params.

Now as far as I understand people are usually interested in the CFIM with respect to a parametrized state rather than a measurement, i.e. the measurement set M being simply all basis states.

In the context of tape transforms, I could just take the operations of the input tape and ignore the measurements. Then create a new tape with those operations and let it output the probabilities. This can then be differentiated and we should in principle have all elements necessary to compute the CFIM.

@Qottmann
Copy link
Contributor Author

One of the design aspects that are unclear to me right now is how a user would interact with such a transform. Do we allow for general qnodes and ignore all measurements (and replace it with probs), or do we say only qnodes with probs as the return type are allowed?

@Qottmann
Copy link
Contributor Author

(tentative) design decision:
There are two alternative ways of computing the CFIM: a) by taking the Hessian of log(p) (eq. (14)) or b) by computing the jacobian of p and recombining them (eq. (15)).
image

We assume that in most cases (15) will be more efficient as the number of probabilities will be larger than the number of parameters. If there is time, I will prototype both and compare them in their performances.

Focusing on variant (15), I will write a transform that strips a qnode of its measurements and returns one that measures probs, qml.transforms.make_probs. The clsasical fisher information matrix function will then look something like

def CFIM(qnode):
    """Computing the classical fisher information matrix (CFIM) using the jacobian of the output probabilities"""
    new_qnode = make_probs(qnode)
    jac = jacobian(new_qnode)
    def wrapper(*args, **kwargs):
        j = jac(*args, **kwargs)
        cfim = _compute_cfim(j)
        return cfim
    return wrapper

Where _compute_cfim(jacobian) computes the cfim given the jacobian of the probabilities.

The other approach, eq. (14) can be similarily done in a similar fashion. The difference is now the transform additionally applies a function to the probs, i.e. the log. Then computing the CFIM is just the probabilities times the Hessian (and summing over the probability components):

def CFIM(qnode):
    """Computing the classical fisher information matrix (CFIM) using the hessian of the log of the output probabilities"""
    new_qnode = make_probs(qnode, func=lambda x: qml.math.log(qml.math.stack(x)))
    hess = hessian(new_qnode)
    def wrapper(*args, **kwargs):
        h = hess(*args, **kwargs)                               # (2**n_wires, num_params, num_params)
        p = qnode(*args, **kwargs)[:, pnp.newaxis, pnp.newaxis] # (2**n_wires, 1, 1)
        return qml.math.sum(h*p, axis=0)
    return wrapper

Base automatically changed from mutual_information to master June 10, 2022 07:08
@rmoyard rmoyard merged commit 51c6708 into master Jun 10, 2022
@rmoyard rmoyard deleted the classicalfisher branch June 10, 2022 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants