Skip to content

Commit

Permalink
Attampting a first solution to the variable qubit size #22. Still doe…
Browse files Browse the repository at this point in the history
…s not update vqe_conf but effectively works with MIDI control #23
  • Loading branch information
Itaborala committed Sep 30, 2024
1 parent 8b68153 commit 6b82389
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 45 deletions.
12 changes: 7 additions & 5 deletions control_to_setup2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ def json_to_csv(json_fp, csv_fp):

mapping_dict = {True: '', False: ' '}
#main_order = ['c', 'e', 'g', 'b']
main_order = ['s1', 's2', 's3', 's4']
key_names = {'s1': 'c', 's2': 'e', 's3': 'g', 's4': 'b'}
sub_order = main_order
ordered_data = {key_names[k]: {key_names[sk]: data[k][sk] for sk in sub_order} for k in main_order}
#main_order = ['s1', 's2', 's3', 's4']
#key_names = {'s1': 'c', 's2': 'e', 's3': 'g', 's4': 'b'}
#sub_order = main_order
#ordered_data = {key_names[k]: {key_names[sk]: data[k][sk] for sk in sub_order} for k in main_order}

data = ordered_data
#data = ordered_data
#Label names need to be sortable according to the matrix order
data = dict(sorted(data.items()))

with open(csv_fp, 'w', newline='') as file:
csv_writer = csv.writer(file)
Expand Down
2 changes: 1 addition & 1 deletion core/vqh_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def update_realtime(self, thread=None):
sys.exit(0)
break
if rt_config["next_problem"]:
json_to_csv('midi/qubo_control.json', 'h_setup_rt.csv')
#json_to_csv('midi/qubo_control.json', 'h_setup_rt.csv')
#sleep(0.05)
self.outlet.bang({"qubos": "h_setup_rt.csv"})
self.core.problem_event.set()
Expand Down
60 changes: 34 additions & 26 deletions midi/vqh_midi_control.scd
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ MIDIIn.connectAll;

var scaledVal = minRange + (val * (maxRange - minRange) / 127).round(0.01); // Scale the value
var data = ~readQUBO.value;
key.postln;
// scaledVal.postln; // Post current state
data[key][key] = scaledVal;
// data[key].postln;
data[key].postln;
~writeQUBO.(data); // Write changes back to JSON

}
Expand Down Expand Up @@ -161,32 +162,35 @@ MIDIIn.connectAll;
};


~label = "s";


~clock_speed_handler = ~createSlideHandler.(\clock_speed, 0.05, 1.0);
~endButtonUp = ~createButtonHandler.(\end, false, 0);
~endButtonDown = ~createButtonHandler.(\end, true, 127);
~nextButton = ~createButtonHandler.(\next_problem, true, 127);
~quboSlider = ~createQUBOSiderHandler.(\s1, -1.0, 1.0);
~quboSlider2 = ~createQUBOSiderHandler.(\s2, -1.0, 1.0);
~quboSlider3 = ~createQUBOSiderHandler.(\s3, -1.0, 1.0);
~quboSlider4 = ~createQUBOSiderHandler.(\s4, -1.0, 1.0);
~quboCoupling12 = ~createCouplingSliderHandler.(\s1, \s2, -1.0, 1.0);
~quboCoupling13 = ~createCouplingSliderHandler.(\s1, \s3, -1.0, 1.0);
~quboCoupling14 = ~createCouplingSliderHandler.(\s1, \s4, -1.0, 1.0);
~quboCoupling23 = ~createCouplingSliderHandler.(\s2, \s3, -1.0, 1.0);
~quboCoupling24 = ~createCouplingSliderHandler.(\s2, \s4, -1.0, 1.0);
~quboCoupling34 = ~createCouplingSliderHandler.(\s3, \s4, -1.0, 1.0);

~quboFlipper1 = ~createQUBOFlipperButton.(\s1);
~quboFlipper2 = ~createQUBOFlipperButton.(\s2);
~quboFlipper3 = ~createQUBOFlipperButton.(\s3);
~quboFlipper4 = ~createQUBOFlipperButton.(\s4);

~quboFlipper12 = ~createQUBOFlipperCoupling.(\s1, \s2);
~quboFlipper13 = ~createQUBOFlipperCoupling.(\s1, \s3);
~quboFlipper14 = ~createQUBOFlipperCoupling.(\s1, \s4);
~quboFlipper23 = ~createQUBOFlipperCoupling.(\s2, \s3);
~quboFlipper24 = ~createQUBOFlipperCoupling.(\s2, \s4);
~quboFlipper34 = ~createQUBOFlipperCoupling.(\s3, \s4);
~quboSlider = ~createQUBOSiderHandler.((~label++"1").asSymbol, -1.0, 1.0);
~quboSlider2 = ~createQUBOSiderHandler.((~label++"2").asSymbol, -1.0, 1.0);
~quboSlider3 = ~createQUBOSiderHandler.((~label++"3").asSymbol, -1.0, 1.0);
~quboSlider4 = ~createQUBOSiderHandler.((~label++"4").asSymbol, -1.0, 1.0);
~quboCoupling12 = ~createCouplingSliderHandler.((~label++"1").asSymbol, (~label++"2").asSymbol, -1.0, 1.0);
~quboCoupling13 = ~createCouplingSliderHandler.((~label++"1").asSymbol, (~label++"3").asSymbol, -1.0, 1.0);
~quboCoupling14 = ~createCouplingSliderHandler.((~label++"1").asSymbol, (~label++"4").asSymbol, -1.0, 1.0);
~quboCoupling23 = ~createCouplingSliderHandler.((~label++"2").asSymbol, (~label++"3").asSymbol, -1.0, 1.0);
~quboCoupling24 = ~createCouplingSliderHandler.((~label++"2").asSymbol, (~label++"4").asSymbol, -1.0, 1.0);
~quboCoupling34 = ~createCouplingSliderHandler.((~label++"3").asSymbol, (~label++"4").asSymbol, -1.0, 1.0);

~quboFlipper1 = ~createQUBOFlipperButton.((~label++"1").asSymbol);
~quboFlipper2 = ~createQUBOFlipperButton.((~label++"2").asSymbol);
~quboFlipper3 = ~createQUBOFlipperButton.((~label++"3").asSymbol);
~quboFlipper4 = ~createQUBOFlipperButton.((~label++"4").asSymbol);

~quboFlipper12 = ~createQUBOFlipperCoupling.((~label++"1").asSymbol, (~label++"2").asSymbol);
~quboFlipper13 = ~createQUBOFlipperCoupling.((~label++"1").asSymbol, (~label++"3").asSymbol);
~quboFlipper14 = ~createQUBOFlipperCoupling.((~label++"1").asSymbol, (~label++"4").asSymbol);
~quboFlipper23 = ~createQUBOFlipperCoupling.((~label++"2").asSymbol, (~label++"3").asSymbol);
~quboFlipper24 = ~createQUBOFlipperCoupling.((~label++"2").asSymbol, (~label++"4").asSymbol);
~quboFlipper34 = ~createQUBOFlipperCoupling.((~label++"3").asSymbol, (~label++"4").asSymbol);
)

a = MIDIFunc.cc({arg ...args; args.postln});
Expand Down Expand Up @@ -270,10 +274,14 @@ var process;

)

~data = ~readQUBO.value;
~data["s4".asSymbol]
~data




~label = "s"
~label++'3'
~quboSliderTest = ~createQUBOSiderHandler.((~label++"4").asSymbol, -1.0, 1.0);
~quboSliderTest.value(60)



Expand Down
2 changes: 1 addition & 1 deletion synth/osc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, ip:str="127.0.0.1", port:int=1450) -> None:
def publish_data(self, data, **kwargs):
print(f'Publishing data: {data}')
#serialized_data = json.dumps(data[0][0].tolist())
serialized_data = [(i, item[1]) for i, item in enumerate(data[0][0].items())]
serialized_data = [(item[0], item[1]) for i, item in enumerate(data[0][0].items())]
print(f'Serialized data: {serialized_data}')

self.client.send_message("/vqh/expval", data[1])
Expand Down
35 changes: 23 additions & 12 deletions synth/osc_examples/vqh_listener.pd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#N canvas 0 18 958 557 12;
#N canvas 960 1218 958 557 12;
#X obj 49 54 netreceive -u -b;
#X obj 49 83 oscparse;
#X msg 49 21 listen 1450;
Expand All @@ -8,32 +8,43 @@
#X obj 49 205 print expval;
#X obj 144 206 print mprob;
#X obj 49 105 route list;
#X obj 266 82 route 0 1 2 3;
#X floatatom 205 123 5 0 0 0 - - - 0;
#X floatatom 244 123 5 0 0 0 - - - 0;
#X floatatom 284 122 5 0 0 0 - - - 0;
#X floatatom 325 121 5 0 0 0 - - - 0;
#X text 271 225 NOTE:VQH uses Big Endian binary notation!;
#X text 375 71 Marginal Probabilities;
#X text 397 44 Marginal Probabilities;
#X floatatom 327 179 5 0 0 0 - - - 0;
#X text 381 150 Energy Expectation Value;
#X obj 57 183 send expval;
#X obj 161 185 send mprob;
#X obj 262 152 receive expval;
#X obj 266 54 receive mprob;
#X obj 266 47 receive mprob;
#X text 306 13 VQH OSC Mapping Example -Itaborala-;
#X obj 238 82 route s0 s1 s2 s3;
#X floatatom 385 123 5 0 0 0 - - - 0;
#X floatatom 424 123 5 0 0 0 - - - 0;
#X floatatom 464 122 5 0 0 0 - - - 0;
#X floatatom 505 121 5 0 0 0 - - - 0;
#X obj 418 82 route p0 p1 p2 p3;
#X connect 0 0 1 0;
#X connect 1 0 8 0;
#X connect 2 0 0 0;
#X connect 4 0 5 0;
#X connect 4 0 3 0;
#X connect 5 0 6 0;
#X connect 5 0 18 0;
#X connect 5 0 17 0;
#X connect 5 1 7 0;
#X connect 5 1 19 0;
#X connect 5 1 18 0;
#X connect 8 0 4 0;
#X connect 9 0 10 0;
#X connect 9 1 11 0;
#X connect 9 2 12 0;
#X connect 9 3 13 0;
#X connect 20 0 16 0;
#X connect 21 0 9 0;
#X connect 19 0 15 0;
#X connect 20 0 22 0;
#X connect 20 0 27 0;
#X connect 22 0 9 0;
#X connect 22 1 10 0;
#X connect 22 2 11 0;
#X connect 22 3 12 0;
#X connect 27 0 23 0;
#X connect 27 1 24 0;
#X connect 27 2 25 0;
#X connect 27 3 26 0;

0 comments on commit 6b82389

Please sign in to comment.