Skip to content

Commit

Permalink
Refactor models module
Browse files Browse the repository at this point in the history
  • Loading branch information
javinoram committed Jul 28, 2024
1 parent c6e0b0a commit 2ebc783
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 460 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push_event_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
- name : Install Packages
run : pip install -r requirements.txt

- name : Run tests hamiltonians
run : pytest tests/test.py
- name : Run tests hamiltonians models
run : pytest tests/model_test.py

4 changes: 2 additions & 2 deletions quantumsim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from quantumsim.ansatz import *
from quantumsim.variational import *
from quantumsim.models import *
from quantumsim.optimizers import *
from quantumsim.lattice import *
from quantumsim.beginstate import *


package_version = '1.0.0'
package_version = '1.0.0'
File renamed without changes.
15 changes: 5 additions & 10 deletions quantumsim/variational/vqe/base.py → quantumsim/models/base.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import numpy as np

"""
Clase base del VQE.
Clase base de los modelos
"""
class vqe_base():
class model_base():
"""
Variables de la clase
"""
hamiltonian= None
qubits = 0

#def cost_function(self, params, ansatz, estimator) -> float:
# if self.hamiltonian is None:
# return 0.0
# result = estimator.run(pubs=[ (ansatz, [self.hamiltonian], [params]) ]).result()
# energy = result[0].data.evs[0]
# return energy

def energies_and_states(self):
if self.hamiltonian is None:
return [], []
Expand All @@ -27,4 +20,6 @@ def get_matrix(self):
if self.hamiltonian is None:
return None
return self.hamiltonian.to_matrix()


def get_hamiltonian(self):
return self.hamiltonian
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .base import vqe_base
from .base import model_base
from qiskit_nature.second_q.mappers import JordanWignerMapper
import numpy as np
from qiskit_nature.second_q.operators import FermionicOp
Expand All @@ -8,7 +8,7 @@
Clase para construir el hamiltoniano usado en el proceso de VQE, hereda metodos de la clase
vqe_base
"""
class fermihubbard_model(vqe_base):
class fermihubbard_model(model_base):

"""
Constructor de la clase
Expand Down
60 changes: 60 additions & 0 deletions quantumsim/models/molecular.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from .base import model_base
from qiskit_nature.units import DistanceUnit
from qiskit_nature.second_q.drivers import PySCFDriver
from qiskit_nature.second_q.mappers import JordanWignerMapper
import numpy as np


class molecule_model(model_base):
mapper = JordanWignerMapper()
params = {}

"""
Constructor de la clase
params: diccionario con los parametros del hamiltoniano
"""
def __init__(self, params):

self.params = params

if "coordinates" not in params:
return

coor = params['coordinates']
atom_string = ""
for i,s in enumerate(params['symbols']):
atom_string += f"{s} {coor[3*i]} {coor[3*i + 1]} {coor[3*i +2]};"

driver = PySCFDriver(
atom=atom_string,
unit=DistanceUnit.ANGSTROM,
basis=params['basis'],
charge=params['charge'],
spin=params['spin']
)

problem = driver.run()
second_q_op, _ = problem.second_q_ops()
self.hamiltonian = self.mapper.map(second_q_op)
return


def set_hamiltonian(self, dist):
atom_string = ""
for i,s in enumerate( self.params['symbols'] ):
atom_string += f"{s} {dist[3*i]} {dist[3*i + 1]} {dist[3*i +2]};"

driver = PySCFDriver(
atom=atom_string,
unit=DistanceUnit.ANGSTROM,
basis=self.params['basis'],
charge=self.params['charge'],
spin=self.params['spin']
)

problem = driver.run()
second_q_op, _ = problem.second_q_ops()
self.hamiltonian = self.mapper.map( second_q_op )
return self.hamiltonian


Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from .base import vqe_base
from .base import model_base
from qiskit.quantum_info import SparsePauliOp

"""
Clase para construir el hamiltoniano usado en el proceso de VQE, hereda metodos de la clase
vqe_base
"""
class spin_model(vqe_base):
class spin_model(model_base):

"""
Constructor de la clase
Expand Down
3 changes: 0 additions & 3 deletions quantumsim/variational/__init__.py

This file was deleted.

2 changes: 0 additions & 2 deletions quantumsim/variational/adapt/__init__.py

This file was deleted.

127 changes: 0 additions & 127 deletions quantumsim/variational/adapt/base.py

This file was deleted.

84 changes: 0 additions & 84 deletions quantumsim/variational/adapt/fermihubbard.py

This file was deleted.

Loading

0 comments on commit 2ebc783

Please sign in to comment.