ariannacrippa / QC_lattice_H

Definition of the Hamiltonian for a lattice model suitable for quantum devices
MIT License
1 stars 1 forks source link

[Pytests] - Should HCLattice class be able to create 1D lattices? #1

Open Itaborala opened 3 months ago

Itaborala commented 3 months ago

Just started creating some test files using pytest, as part of the code improvement roadmap. (check the test_files branch)

While testing the instantiation of the HCLattice class for 1D lattices (commit 5f26ca4), I ran into the error below. Is this expected behaviour?

from HC_Lattice import HCLattice

n_sites = [3]
periodic = [True]
HCLattice(n_sites, periodic)
test_HC_Lattice.py:14: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
HC_Lattice.py:101: in __init__
    self.func_qstatic_dist()
HC_Lattice.py:887: in func_qstatic_dist
    r_list[i] = self.distance_f(*dd.keys())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <HC_Lattice.HCLattice object at 0x74041aa44160>, points = (0,)

    def distance_f(self, *points):
        if len(points) < 2:
>           raise ValueError(
                "At least two points are required to calculate the distance."
            )
E           ValueError: At least two points are required to calculate the distance.

HC_Lattice.py:772: ValueError
ariannacrippa commented 3 months ago

Yes, I think this could happen sometime since I defined a lot of functions and tested them only for 2+1D, so for every other cases I usually put a raise error to fill the gap. In this and every other case I suggest to a) leave it as it is and check that the function is called only in certain cases so we don't get error messages OR b) extend the action of the function (but of course this requires more work)

EmilOtisRosanowski commented 3 months ago

I guess this could also just be due to too few lattice points. At least when I tried to create a [2,1] lattice, the same happened.