diff --git a/symmer/operators/base.py b/symmer/operators/base.py index 3c853d4d..688d58df 100644 --- a/symmer/operators/base.py +++ b/symmer/operators/base.py @@ -1,7 +1,7 @@ import os import quimb from symmer.operators.utils import * -import ray +from ray import put, get, remote import numpy as np import pandas as pd import networkx as nx @@ -829,8 +829,8 @@ def expval(self, psi: "QuantumState") -> complex: """ if self.n_terms > 1: # parallelize if number of terms greater than one - psi_ray_store = ray.put(psi) - expvals = np.array(ray.get( + psi_ray_store = put(psi) + expvals = np.array(get( [single_term_expval.remote(P, psi_ray_store) for P in self])) else: expvals = np.array(single_term_expval(self, psi)) @@ -2399,7 +2399,7 @@ def get_ij_operator(i:int, j:int, n_qubits:int, else: return ij_symp_matrix, coeffs -@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"), diff --git a/symmer/operators/independent_op.py b/symmer/operators/independent_op.py index 30b4bf55..ffd46673 100644 --- a/symmer/operators/independent_op.py +++ b/symmer/operators/independent_op.py @@ -4,7 +4,7 @@ import multiprocessing as mp from symmer.operators.utils import _rref_binary, _cref_binary, check_independent from symmer.operators import PauliwordOp, QuantumState, symplectic_to_string, single_term_expval -import ray +from ray import put, get, remote class IndependentOp(PauliwordOp): """ @@ -296,8 +296,8 @@ def update_sector(self, # self.coeff_vec = np.array( # list(pool.starmap(assign_value, [(S, ref_state, threshold) for S in self])) # ) - ref_state_ray_store = ray.put(ref_state) - self.coeff_vec = np.array(ray.get( + ref_state_ray_store = put(ref_state) + self.coeff_vec = np.array(get( [single_term_expval.remote(S, ref_state_ray_store) for S in self])) # set anything below threshold to be zero self.coeff_vec[np.abs(self.coeff_vec) Tuple[float, np.array, np.array]: nu_list[:,~self.fixed_ev_mask] = np.array(list(itertools.product([-1,1],repeat=np.sum(~self.fixed_ev_mask)))) # # optimize over all discrete value assignments of nu in parallel - noncon_H = ray.put(self.NC_op) - tracker = np.array(ray.get( + noncon_H = put(self.NC_op) + tracker = np.array(get( [get_noncon_energy.remote(noncon_H, nu_vec) for nu_vec in nu_list])) # with mp.Pool(mp.cpu_count()) as pool: @@ -879,7 +879,7 @@ def energy_xUSO(self) -> Tuple[float, np.array, np.array]: return self.NC_op.get_energy(nu_vec), nu_vec -@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"), diff --git a/symmer/utils.py b/symmer/utils.py index 6cefe6e7..1d4b5599 100644 --- a/symmer/utils.py +++ b/symmer/utils.py @@ -8,7 +8,7 @@ from scipy.sparse import kron as sparse_kron from symmer.operators.utils import _rref_binary import multiprocessing as mp -import ray +from ray import put, get, remote import os # from psutil import cpu_count @@ -270,20 +270,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"),