UCL-CCS / symmer

An efficient Python-based framework for implementing qubit subspace methods, reducing the resource requirements for near-term quantum simulations.
MIT License
37 stars 9 forks source link

taper_it not working from python script due to multiprocessing module #136

Closed mattkiservw closed 1 year ago

mattkiservw commented 1 year ago

In the same python conda environment, line 28 of the below code (basically copied from one of your example notebooks) results in the file restarting multiple times and then eventually hitting an error when I use a python file rather than in a Jupyter notebook, where it does work. I am on a Mac if this matters. I have tried on two different computers and the problem persists.

The error goes down to symmer/operators/independent_op.py, line 238, in update_sector with mp.Pool(mp.cpu_count()) as pool:

Which then raises an issue into the multiprocessing module, ultimately leading to a RuntimeError and then An attempt has been made to start a new process before the current process has finished its bootstrapping phase.

Code that reproduces the error below, the hamiltonian_data folder (copied from the repo) is in the same directory as the python/ipynb files

Screenshot 2023-05-04 at 15 50 57

import numpy as np import os import json from symmer.operators import PauliwordOp, QuantumState from symmer.projection import QubitTapering

file_dir = os.getcwd() ham_data_dir = os.path.join(file_dir, 'hamiltonian_data')

if not os.path.isdir(ham_data_dir): raise ValueError('cannot find data dir')

filename = 'Be_STO-3G_SINGLET_JW.json'

if filename not in os.listdir(ham_data_dir): raise ValueError('unknown file')

with open(os.path.join(ham_data_dir, filename), 'r') as infile: data_dict = json.load(infile) print("Successfully loaded data")

hf_state = QuantumState(np.asarray(data_dict['data']['hf_array'])) # Hartree-Fock state

hamiltonian_pauliword = PauliwordOp.from_dictionary(data_dict['hamiltonian'])

qubit_taper_object = QubitTapering(hamiltonian_pauliword)

H_taper = qubit_taper_object.taper_it(ref_state=hf_state)

print("completed")

mattkiservw commented 1 year ago

Found and figured out how to use the command_line.py file.