Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse matrix representation for Ising models #44

Closed
wants to merge 2 commits into from

Conversation

IraitzM
Copy link

@IraitzM IraitzM commented Dec 13, 2023

I thought it could be usefull to have a function that converts Ising model Dict into Sparse matrix representation.

@zmorrell
Copy link
Collaborator

Awesome, thanks. I could see something along these lines being a useful bit of functionality for a people's potential workflows. I just want to check a few things regarding your intended functionality and use case.

First, It strikes me that this functionality as defined here is captured by the functionality in hamiltonian_transverse_ising, for example with a call like hamiltonian_transverse_ising(ising_model, AS_LINEAR, 1) you can currently reproduce this functionality. As I see it, this submission does this same thing, with a reduced overhead by not adding in a 0 weighted X field. Is the overhead associated with computing the X component worth defining a new function for the instances you are running? If so, I think for the sake of readability, brevity, and code re-use the current implementation could be re-written as something like

function ising_to_matrix(ising_model::Dict)
    n = _check_ising_model(ising_model)
    z_component = SparseArrays.spzeros(2^n, 2^n)
    for (tup,w) in ising_model
        z_component += _kron_Z(n, tup, w)
    end
    return z_component
end

Second, by writing it this way, you are effectively converting your Ising model to an explicit computation of all of its eigen-energies, and effectively computing every solution of the Ising model which takes exponential time and space - Is this what you want, or were you wanting something more like an ising_to_adjacency_matrix(ising_model) function? If it is the former, do you want the solutions represented as a matrix, or is just a dense vector representing the diagonal sufficient for your use case?

Thanks again.

@IraitzM
Copy link
Author

IraitzM commented Dec 13, 2023

Thanks @zmorrell! Indeed I did not think it though as you pointed out hamiltonian_transverse_ising(ising_model, ..., 1.0) would represent the same object (the object I was looking for at least).

Will close the PR and apologies for the extra work :)

@IraitzM IraitzM closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants