Metadata-Version: 2.4
Name: hivqe_qiskit_function_utils
Version: 0.3.0
Summary: Client-side utilities for use with Qunova Computing's HI-VQE Qiskit Function.
Author-email: Rowan Pellow-Jarman <pellow.r@qunovacomputing.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/qunovacomputing/hivqe_qiskit_function_utils
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: qiskit-ibm-catalog
Requires-Dist: cryptography
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"

# HI-VQE Qiskit Function Utilities

This package is intended to provide some utilities to help users of
[Qunova's HI-VQE Qiskit
Function](https://quantum.cloud.ibm.com/functions?id=qunova-hivqe-chemistry).

## Current Features
### Helps licensed users submit their license token to the function with encryption.
The below example shows how this package can be used to wrap the
HI-VQE Qiskit Function retrieved from the Qiskit IBM Catalog to
properly submit your token:
```python
import math
import h5py
from qiskit_ibm_catalog import QiskitFunctionsCatalog, QiskitServerless
from hivqe_qiskit_function_utils import FunctionWrapper


catalog = QiskitFunctionsCatalog(token="your_qiskit_functions_catalog_token", 
                                 channel="ibm_quantum_platform", 
                                 instance="your_ibm_instance")

serverless = QiskitServerless(token="your_qiskit_functions_catalog_token", 
                              channel="ibm_quantum_platform", 
                              instance="your_ibm_instance")

molecule_geometry = f"""
O 0 0 0;
H {-0.957*math.sin(math.radians(104.5)/2.0)} {0.957*math.cos(math.radians(104.5)/2.0)} 0;
H {0.957*math.sin(math.radians(104.5)/2.0)} {0.957*math.cos(math.radians(104.5)/2.0)} 0
"""

hivqe = FunctionWrapper(token="your_hivqe_license_token", 
                        function=catalog.load("qunova/hivqe-chemistry"))

job = hivqe.run(
    geometry=molecule_geometry,
    backend_name="ibm_torino",
    max_states=10000,
    max_expansion_states=1000,
    hivqe_options={"ansatz": "epa", "max_iter": 10},
)

result = job.result()

# Extract the results
energy = result["energy"]
results_file_name = result["results_file_name"]
energy_variance = result["energy_variance"]
total_energy_history = result["energy_history"]

# Download the h5 results file to the current directory
serverless.file_download(results_file_name, 
                         catalog.load("qunova/hivqe-chemistry"))

# Read all data from the results file
with h5py.File(results_file_name, "r") as f:
    states = f["states"][:]
    eigenvector = f["eigenvector"][:]
    energy_history = f["energy_history"][:]
    final_energy = f["final_energy"][0]
    final_energy_variance = f["final_energy_variance"][0]

# Check the logs
logs = job.logs()
```
