qiskit-nature
qiskit-nature copied to clipboard
Heisenberg model
Summary
This PR is related with the Issue #577 Heisenberg model. The main idea behind it, is the addition of the Heisenberg model aiming the expansion of the lattice models.
Details and comments
I used the ising_model.py to guide the process of rewriting my original code, to avoid any conflicts with the logic behind the construction of the models through a lattice. However, I had to add some different aspects to heisenberg_model.py, once this model is more general than the Ising model, actually the Ising model is a specific case of Heisenberg model ( J_x = J_y= 0, J_z = 1 and h = 1). I tried to follow the logic of getting all information to build the model of the lattice, but this approach could lead to some problems, once we have XX, YY and ZZ terms, multiplied by constants J_x, J_y and J_z, that not necessarily must be equal. Another difference between the models is that in the Heisenberg model the anisotropic term/external magnetic field is not restricted to the x-axis. Thus, I thought it would be better if I just used the lattice to get the number of qubits and the connection between the nodes, instead of making use of multigraphs. Then, if we want to some special configuration we need to give the HeisenbergModel class two dictionaries, one to set the model constants, and other to set the direction of the external magnetic field, if the user does not pass any dictionaries to the method, a default configuration will be used, the ferromagnetic without an external magnetic field. To finish my comments, I would like to ask an opinion of the reviewers about the construction of the code, once some of you could have a better approach to the construction of the model.
Pull Request Test Coverage Report for Build 2873192820
- 35 of 38 (92.11%) changed or added relevant lines in 2 files are covered.
- 3 unchanged lines in 1 file lost coverage.
- Overall coverage decreased (-0.002%) to 85.546%
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
---|---|---|---|
qiskit_nature/second_q/properties/heisenberg_model.py | 34 | 37 | 91.89% |
<!-- | Total: | 35 | 38 |
Files with Coverage Reduction | New Missed Lines | % |
---|---|---|
qiskit_nature/drivers/second_quantization/psi4d/psi4driver.py | 3 | 84.43% |
<!-- | Total: | 3 |
Totals | |
---|---|
Change from base Build 2847983183: | -0.002% |
Covered Lines: | 17578 |
Relevant Lines: | 20548 |
💛 - Coveralls
Hi @jvscursulim, thanks for the contribution. I had a first pass and this looks quite good already. As this is a new feature can you please add a release note ?
Hi @jvscursulim, thanks for the contribution. I had a first pass and this looks quite good already. As this is a new feature can you please add a release note ?
Thanks @pbark for the comments. I'll start work on the realease note.
@mrossinek I tried to create a new version of the HeisenbergModel
class following your instructions, but I'm having some troubles to inject the coupling constants J
(a tuple
) and the external magnetic field B
(a tuple
) as you suggested. In order to solve this problem, I put J
and B
as input of the second_q_ops()
method and defined some default values to them. My problem with J
and B
injection using the method that you suggested is that I don't know how to deal with it when the tuple J
has different coupling constants and the tuple B
only has one value nonzero, that means we are applying an external magnetic field in one specific direction. I hope that you can understand what I'm saying, but if you don't, the things I'm trying to say are present in the following wikipedia article: https://en.wikipedia.org/wiki/Quantum_Heisenberg_model
I don't actually fully understand what the problem is in that scenario. It should be identical to what you had before, just using tuples instead of named dictionary entries..
That said, second_q_ops()
cannot take any arguments. You must provide J
and B
as arguments to __init__
and store them as instance variables on self
@mrossinek I changed the docstring in order to explain better coupling_constants
and ext_magnetic_field
. Also, I added more tests as you requested. I added one test to see if the class are creating the right model with parameters just in x and y axes, other to see the with an external magnetic field in all directions (x, y and z) and I also added a test to check the model in a triangular lattice with an external magnetic field in y direction.
@woodsp-ibm if you could have a look here, too, that would be great :slightly_smiling_face:
LGTM. Thanks Victor for completing another contribution to Qiskit Nature!
Thanks Steve, I'm glad in complete another contribution to Qiskit Nature!