From 5c295657c44a9eb1238e202db24ae290057eb5f6 Mon Sep 17 00:00:00 2001 From: jnorambu Date: Tue, 7 May 2024 20:08:39 -0400 Subject: [PATCH] Test module and github action --- .github/workflows/push_event_workflow.yml | 18 ++++++++++++++++++ quantumsim/variational/vqe/molecular.py | 3 +-- requirements.txt | 4 ++-- tests/__init__.py | 0 tests/test.py | 20 ++++++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/push_event_workflow.yml create mode 100644 tests/__init__.py create mode 100644 tests/test.py diff --git a/.github/workflows/push_event_workflow.yml b/.github/workflows/push_event_workflow.yml new file mode 100644 index 0000000..5550066 --- /dev/null +++ b/.github/workflows/push_event_workflow.yml @@ -0,0 +1,18 @@ +name: Push Event Workflow 🐍 + +on: push + +jobs: + unit-testing: + runs-on: ubuntu-latest + + steps: + - name : Checkout code + uses : actions/checkout@v4 + + - name : Install Packages + run : pip install -r requirements.txt + + - name : Run tests hamiltonians + run : pytest tests/test.py + diff --git a/quantumsim/variational/vqe/molecular.py b/quantumsim/variational/vqe/molecular.py index 6fd5135..007bb2d 100644 --- a/quantumsim/variational/vqe/molecular.py +++ b/quantumsim/variational/vqe/molecular.py @@ -55,6 +55,5 @@ def __init__(self, symbols, coordinates, params= None): basis= self.basis, method= self.method, active_electrons=self.active_electrons, - active_orbitals=self.active_orbitals, - load_data=True) + active_orbitals=self.active_orbitals) diff --git a/requirements.txt b/requirements.txt index 842bf0c..87db180 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,8 +9,8 @@ pennylane-qiskit qiskit_ibm_provider pyyaml networkx -basis-set-exchange ipykernel pennylane-lightning jaxopt -optax \ No newline at end of file +optax +pytest diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..c1101b4 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,20 @@ +import pennylane as qml +from pennylane import numpy as np +from quantumsim.variational.vqe import vqe_spin, vqe_fermihubbard, vqe_molecular + +#Test the hamiltonian of the h2 molecule +def test_hamiltonian_molecule(): + #pennylane hamiltonian + elements=["H", "H"] + coord=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 1.0]) + H,q = qml.qchem.molecular_hamiltonian(elements, coord) + coef, ter = H.terms() + H = qml.Hamiltonian(coef ter) + #vqepy class + + Hvqe = vqe_molecular(elements, coord, {}) + coefvqe, tervqe = Hvqe.terms() + Hvqe = qml.Hamiltonian(coefvqe, tervqe) + assert H.compare(Hvqe.hamiltonian) + +