Closed IraitzM closed 6 months ago
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.
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 :)
I thought it could be usefull to have a function that converts Ising model Dict into Sparse matrix representation.