Skip to content

Commit

Permalink
Merge branch 'ind_op_fix' into update_qiskit
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWeaving committed Oct 8, 2024
2 parents ffc1d79 + 4245dae commit d1d2d32
Show file tree
Hide file tree
Showing 6 changed files with 1,243 additions and 1,226 deletions.
2,439 changes: 1,227 additions & 1,212 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ license = "MIT"
[tool.poetry.dependencies]
python = "^3.8"
openfermion = "^1.6.1"
qiskit = "^1.2.4"
cached-property = "^1.5.2"
qiskit = "0.46"
pydocstyle = "^6.1.1"
isort = "^5.10.1"
black = "^24.3.0"
Expand Down
3 changes: 2 additions & 1 deletion symmer/evolution/variational_optimization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from cached_property import cached_property
from qiskit.quantum_info import Statevector
# from qiskit.opflow import CircuitStateFn # old qiskit function replaced by Statevector
from qiskit import QuantumCircuit
from symmer import process, QuantumState, PauliwordOp
from symmer.operators.utils import (
Expand Down Expand Up @@ -83,7 +84,7 @@ def get_state(self,
if self.expectation_eval == 'observable_rotation':
return list(zip(evolution_obj, -2*x))
else:
state = Statevector(evolution_obj.bind_parameters(x))
state = Statevector(evolution_obj.bind_parameters(x)).data
if self.expectation_eval == 'dense_array':
return state.to_matrix().reshape([-1,1])
elif self.expectation_eval == 'sparse_array':
Expand Down
2 changes: 1 addition & 1 deletion symmer/operators/noncontextual_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def draw_graph_structure(self,
weights = [G[u][v]['weight'] for u,v in edges]
nx.draw(G, pos, edge_color=colors, width=weights,
node_color=node_colour, node_size=node_size, ax=axis)

def noncontextual_generators(self) -> None:
"""
Find an independent generating set for the noncontextual operator.
Expand Down
9 changes: 5 additions & 4 deletions symmer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from scipy.sparse import csr_matrix
from scipy.sparse import kron as sparse_kron
from symmer.operators.utils import _rref_binary
import ray
# import ray
from ray import remote, get
import os
# from psutil import cpu_count

Expand Down Expand Up @@ -286,20 +287,20 @@ def get_sparse_matrix_large_pauliwordop(P_op: PauliwordOp) -> csr_matrix:
n_chunks = os.cpu_count()
if (n_chunks<=1) or (P_op.n_terms<=1):
# no multiprocessing possible
mat = ray.get(_get_sparse_matrix_large_pauliwordop.remote(P_op))
mat = get(_get_sparse_matrix_large_pauliwordop.remote(P_op))
else:
# plus one below due to indexing (actual number of chunks ignores this value)
n_chunks += 1
P_op_chunks_inds = np.rint(np.linspace(0, P_op.n_terms, min(n_chunks, P_op.n_terms+1))).astype(set).astype(int)
P_op_chunks = [P_op[P_op_chunks_inds[ind_i]: P_op_chunks_inds[ind_i + 1]] for ind_i, _ in
enumerate(P_op_chunks_inds[1:])]
tracker = np.array(ray.get(
tracker = np.array(get(
[_get_sparse_matrix_large_pauliwordop.remote(op) for op in P_op_chunks]))
mat = reduce(lambda x, y: x + y, tracker)

return mat

@ray.remote(num_cpus=os.cpu_count(),
@remote(num_cpus=os.cpu_count(),
runtime_env={
"env_vars": {
"NUMBA_NUM_THREADS": os.getenv("NUMBA_NUM_THREADS"),
Expand Down
14 changes: 7 additions & 7 deletions tests/test_approximate/test_approximate_tensor_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def test_from_dictionary(
# Testing QUIMB dmrg sovler #
############################################

def test_find_groundsate_quimb(
pauli_list_1,
coeff_vec_1
):
MPO = MPOOp(pauli_list_1, coeff_vec_1)
# def test_find_groundsate_quimb(
# pauli_list_1,
# coeff_vec_1
# ):
# MPO = MPOOp(pauli_list_1, coeff_vec_1)

mpostate = find_groundstate_quimb(MPO)
# mpostate = find_groundstate_quimb(MPO)

assert(type(mpostate) == QuantumState)
# assert(type(mpostate) == QuantumState)

0 comments on commit d1d2d32

Please sign in to comment.