Skip to content

Commit

Permalink
Cleaning up and removing old dependencies pt1. see #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Itaborala committed Jun 21, 2024
1 parent 1868266 commit 6f203e1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 76 deletions.
26 changes: 16 additions & 10 deletions VQH.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Global variables
import config

from core.vqh_core_old import VQH
#from core.vqh_core_old import VQH
from core.vqh_core_new import VQHCore, VQHController

# Event Management
Expand Down Expand Up @@ -86,7 +86,7 @@ def list_active_threads():
print(f"Thread Name: {thread.name}, Alive: {thread.is_alive()}")


def CLI(vqh, vqh_core, vqh_controller):
def CLI(vqh_core, vqh_controller):
global progQuit, comp, last, reset, generated_quasi_dist, comp_events
generated_quasi_dist = []

Expand All @@ -112,53 +112,59 @@ def CLI(vqh, vqh_core, vqh_controller):

# Main VQH Command
elif x[0] == 'runvqe':
raise ValueError('This command is deprecated. Use "source" instead.')
if len(x) == 1:
print("running VQE")
#generated_quasi_dist, generated_values = vqh.run_vqh(globalsvqh.SESSIONPATH)
vqh.runvqe(config.SESSIONPATH)
#vqh.runvqe(config.SESSIONPATH)
else:
print('Error! Try Again')

# Sonify From a previously generated VQE result in the session folder
elif x[0] == 'playfile':
raise ValueError('This command is deprecated. Use "source file + son" instead.')
son_type = 1
if len(x) == 3:
son_type = int(x[2])
#playfile(x[1], config.SESSIONPATH, son_type)
vqh.playfile(x[1], config.SESSIONPATH, son_type)
#vqh.playfile(x[1], config.SESSIONPATH, son_type)

# Same as using ctrl+. in SuperCollider
elif x[0] == 'stop':
raise ValueError('This command is deprecated. ')
#sc.freeall()
vqh.stop_sc_sound()
#vqh.stop_sc_sound()

# Sonify the last generated VQE result
elif x[0] == 'play':
raise ValueError('This command is deprecated. Use "son" instead.')
if generated_quasi_dist != []:
son_type = 1
if len(x) == 2:
son_type = int(x[1])
#sc.sonify(generated_quasi_dist, generated_values, son_type)
vqh.play(son_type)
#vqh.play(son_type)
else:
print("Quasi Dists NOT generated!")

elif x[0] == 'map':
raise ValueError('This command is deprecated. Use "son" instead.')
if vqh.data:
son_type = 1
if len(x) == 2:
son_type = int(x[1])
#sc.sonify(generated_quasi_dist, generated_values, son_type)
vqh.map_sonification(son_type)
#vqh.map_sonification(son_type)

else:
print("Quasi Dists NOT generated!")
elif x[0] == 'mapfile':
raise ValueError('This command is deprecated. Use "source file + son" instead.')
son_type = 1
if len(x) == 3:
son_type = int(x[2])
#playfile(x[1], config.SESSIONPATH, son_type)
vqh.mapfile(x[1], config.SESSIONPATH, son_type)
#vqh.mapfile(x[1], config.SESSIONPATH, son_type)


elif x[0] == 'realtime' or x[0] == 'rt':
Expand Down Expand Up @@ -265,7 +271,7 @@ def CLI(vqh, vqh_core, vqh_controller):
config.SESSIONPATH = args.sessionpath
config.HW_INTERFACE = args.platform

vqh = VQH(args.protocol, args.platform)
#vqh = VQH(args.protocol, args.platform)
if args.process_mode == 'file':
vqh_core = VQHCore('file', args.process, args.platform, args.rt_son, args.process_mode, args.sessionpath)
else:
Expand All @@ -288,7 +294,7 @@ def CLI(vqh, vqh_core, vqh_controller):
qubo_vis = multiprocessing.Process(target=update_qubo_visualization, args=(pquit,))
qubo_vis.start()

CLI(vqh, vqh_core, vqh_controlller)
CLI(vqh_core, vqh_controlller)
pquit.value = True
print('Exited VQH')
list_active_threads()
3 changes: 0 additions & 3 deletions core/vqh_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ def connect(self):
def get_backend(self):
pass

@abstractmethod
def optimize(self):
pass

class MappingInterface:

Expand Down
4 changes: 0 additions & 4 deletions core/vqh_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ def run_mapper(self) -> None:

sleep(self.clock_speed)

def update_clock_speed(self, speed: int) -> None:
with self.clock_lock:
self.clock_speed = speed
#print(f"Clock speed updated to {speed}")

def stop(self) -> None:
self.thread.join()
Expand Down
12 changes: 0 additions & 12 deletions util/inlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,3 @@ def __init__(self, target_instance, target_attribute):
def update(self, message):
setattr(self.target_instance, self.target_attribute, message)


class InletLinkedAttribute:
def __init__(self, setter_method):
self.setter_method = setter_method
self.lock = Lock()

def __get__(self, instance, owner):
return self.getter(instance)

def __set__(self, instance, value):
with self.lock:
self.setter_method(value)
40 changes: 0 additions & 40 deletions vqe/vqe_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,46 +45,6 @@ def iteration_callback(self, sample, exp_value, handler):
# handler((amps, exp_value))
handler((amps, exp_value))



def run_segmented(self, iteration_handler):

'''Run harmonizer algorithm for list of qubos and list of iterations. VQE is performed for the i-th qubo for i-th number of iterations.'''
#global PATH

print('SEGMENTED')

self.handler = iteration_handler
# loop over qubos
count = 0
while self.active:

print(f'Next Segment: #{count}')

# Load latest config file
with open("vqe_conf.json") as cfile:
kwargs = json.load(cfile)

operator, self.variables_index = self.protocol.encode(self.problem)

#Optimizer TODO: Include the iteration counter somehow
optimizer = self.return_optimizer(
kwargs['optimizer_name'], kwargs['iterations'][0])
ansatz = EfficientSU2(num_qubits=len(self.variables_index), reps=kwargs['reps'], entanglement=kwargs['entanglement'])

# Initial point
if count == 0:
initial_point = np.zeros(ansatz.num_parameters)
ansatz_temp = copy.deepcopy(ansatz)
vqe_experiment = SamplingVQE()
vqe_experiment.update_config()
result, binary_probabilities, expectation_values = vqe_experiment.run_vqe(
ansatz_temp, operator, optimizer, initial_point, callback=(self.vqe_callback, iteration_handler))


# Set initital point for next qubo to be the optimal point of the previous qubo
initial_point = result.x

def init_point(self):
if self.num_parameters == 0:
print('No parameters found')
Expand Down
8 changes: 1 addition & 7 deletions vqe/vqe_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import config
from shutil import copy2

from abstract_classes import VQHProtocol

from core.vqh_interfaces import QuantumHardwareInterface

Expand All @@ -44,12 +43,7 @@ class SamplingVQE():


def __init__(self):
self.config = {}

def update_config(self):
with open("vqe_conf.json", 'r') as cfile:
self.config = json.load(cfile)

pass


def run_vqe(self, ansatz, operator, optimizer, initial_point, callback=None):
Expand Down

0 comments on commit 6f203e1

Please sign in to comment.