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

Add caching capabilities to QiskitDevice. #165

Open
antalszava opened this issue Dec 10, 2021 · 4 comments
Open

Add caching capabilities to QiskitDevice. #165

antalszava opened this issue Dec 10, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@antalszava
Copy link
Contributor

The PennyLane QubitDevice class allows caching certain circuit executions. Once the same circuit is being executed multiple times, cached values may be used to provide the result of circuit executions.

This capability could also be added to QiskitDevice.

@antalszava antalszava linked a pull request Dec 10, 2021 that will close this issue
@josh146
Copy link
Member

josh146 commented Dec 12, 2021

@antalszava I'm curious if the caching in the device is superceded by the caching in the qml.execute function?

This new caching capability is accessible via the new QNode:

dev = qml.device('qiskit.aer', wires=2)

cache = {}

@qml.qnode(dev, cache=cache)
def expval_circuit(params):
    qml.templates.BasicEntanglerLayers(params, wires=wires, rotation=qml.RX)
    return qml.expval(qml.Hermitian(hamiltonian, wires=wires))

@qml.qnode(dev, cache=cache)
def var_circuit(params):
    qml.templates.BasicEntanglerLayers(params, wires=wires, rotation=qml.RX)
    return qml.var(qml.Hermitian(hamiltonian, wires=wires))
>>> print(expval_circuit(params), var_circuit(params)))
-2.6224875809703287, 0.011605015096940896
>>> print(cache)
{-2104543859499562169: array([-2.62248758]), 3268478774057874589: array([0.01160502])}
>>> print(expval_circuit(params), var_circuit(params)))  # evaluate QNodes again
-2.6224875809703287, 0.011605015096940896
>>> dev.num_executions  # only the first two executions will register
2

@antalszava
Copy link
Contributor Author

@josh146 oh that's a great point! I think so 🤔 Should the QubitDevice caching ability be deprecated then? We could have it on the roadmap.

@josh146
Copy link
Member

josh146 commented Dec 14, 2021

Good idea!

@antalszava
Copy link
Contributor Author

Cool, added it 👍

@dime10 dime10 added the enhancement New feature or request label May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants