Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
462 changes: 210 additions & 252 deletions algorithms/qml/qsvm/qsvm.ipynb

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions algorithms/qml/qsvm/qsvm.qmod
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
qfunc main(output qbv: qbit[]) {
allocate(ceiling(2 / 2), qbv);
bloch_sphere_feature_map(2, qbv);
qfunc bloch_feature_map(data: real[], qba: qbit[]) {
repeat (i: ceiling(data.len / 2)) {
RX(data[2 * i] / 2, qba[i]);
}
repeat (i: floor(data.len / 2)) {
RZ(data[(2 * i) + 1], qba[i]);
}
}

cscope ```
qsvm_results = qsvm_full_run(
train_data=[[2.112186432983832, 0.44678210208296076], [1.4302388641836115, 2.0500863077201803], [1.7195292520528696, 2.155495109429753], [2.350606859600729, 1.3521944997967792], [2.1639392550749834, 2.858154321993804], [0.7415213200617944, 0.9960941727006177], [1.7052044687627945, 1.746156268650723], [1.154481655851151, 1.6296850849870834], [1.178550834103221, 2.4896666171792288], [1.4354595109691861, 2.4579563949501426], [1.302182045580439, 1.8007507228484583], [1.9572970134814875, 1.9123582698010868], [1.6106791225734967, 1.2793841361849436], [1.290997768246414, 0.7328787758880366], [1.4520918763727126, 1.5493209353369237], [1.3969974236871332, 1.8014514945519902], [1.977199796578803, 2.3384223503638606], [1.1275811281170995, 2.324466934392206], [1.3866941108254505, 1.529613601296024], [0.8031123903491375, 1.5721256347123322], [2.6790428274664535, 4.987426996112025], [2.4933103414105124, 5.14388063922973], [2.3501842146874936, 4.917084078977774], [4.178707007615895, 4.460515918834162], [2.948493219124173, 5.4123702911268765], [2.984282159194407, 5.1227667518958695], [2.5769216299750366, 4.508558046516978], [3.592064487915955, 5.555048347762887], [2.396370386221024, 4.870008037808379], [3.0969491698930156, 5.34962991789807], [2.755586029403162, 5.688202501088769], [3.396770558929631, 5.388148675378706], [2.9479167412155634, 5.8933575622716505], [2.613003217938794, 4.706244309823174], [3.1892281958306725, 5.524828040588774], [3.4174852452652087, 4.9812521745298435], [3.236577921191584, 4.888258645409059], [3.354555258869891, 5.034232387617792], [2.886158263159518, 5.167880953936314], [3.0219487270064307, 5.351739891114873]],
train_labels=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
test_data=[[0.6475853396083217, 2.6648523585281274], [1.6805735034770934, 1.049397479428777], [1.46299147986523, 1.0880345107571334], [0.462038416861388, 2.207975364079006], [1.9742863568977997, 1.1367153074429202], [2.1781048480152916, 2.695087602824646], [1.8195500455798252, 1.5164675196201265], [1.1401978420938244, 1.3495496042796211], [0.6947839492447285, 2.684748023240193], [1.7573861234655683, 2.4635344057172124], [1.02857178651341, 2.657056490213285], [1.8413827951912136, 2.176299339137693], [1.33429774903843, 1.292664167472649], [1.7184797782418564, 2.6783094865495167], [1.4083434585872008, 1.5892753245243099], [1.583446844095974, 2.1245052078981974], [1.2354102703604102, 2.1969029938868743], [2.1230955069529176, 1.645771963454583], [1.2936163063518098, 2.03031669517304], [1.4311549417223508, 2.1843803457832633], [3.391532075577815, 4.578028423647197], [2.6536189147079026, 5.543353070632269], [3.352438397103028, 5.406993967686264], [3.866512258343515, 5.641172938446053], [2.8560353801343172, 6.283185307179586], [3.1285020398361647, 5.795896963495207], [2.985742534139181, 4.867246107277921], [4.127951174239671, 5.882165364047927], [3.539466688506218, 4.66570351474424], [3.4070502281205552, 5.092864917592646], [2.8183612727773415, 5.289536417337684], [3.4729439056459084, 6.180328580824684], [2.8661529796713117, 4.95127980897578], [3.2192345891371756, 4.910437950670493], [2.8853962708105594, 5.274430957787284], [3.5415359574732497, 4.991918076818947], [3.4916147183074706, 5.886975181053254], [3.0991699322110025, 4.783691465818289], [3.4013226663308225, 4.749922893794449], [2.656788555634747, 5.104747197627783]],
test_labels=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
predict_data=[[0.9811440346538475, 1.5462800543732582], [2.1949262869084927, 1.0358013632909908], [1.7048706634628803, 1.4014678085835548], [1.2739358806925953, 0.6115754338877866], [0.6174425005849159, 2.0358927355135936], [1.6523417482007734, 0.9222481821966263], [0.7300525863052175, 1.1710853402857748], [0.4577747116111941, 1.7493595496304872], [1.8241751561761508, 1.3534955118043435], [1.3886315659624247, 2.494784307703368], [1.6905896718904094, 1.0768485551382758], [1.3895240864715106, 1.8568024446745914], [1.6585755659513455, 1.7036356008862523], [0.9046474633499264, 1.1392302611294014], [0.7130388391077676, 1.984915340265877], [1.5709575191408134, 1.637503844388876], [0.8284554279130794, 2.109172285606834], [0.8853853711248996, 2.135029086981866], [1.0023940082413283, 2.8048949846403453], [1.2388998395125284, 2.391540984718196], [3.018728391028778, 4.845684719753612], [3.083629721212037, 5.1506663321503074], [3.7531491079435564, 5.091859232676953], [3.5309511753612988, 5.564397956886731], [3.523385073048796, 4.553258712777688], [2.394841287844583, 5.355288217100166], [3.191156247800532, 5.401910488982688], [2.8343038553971556, 5.439747738100138], [3.343281609521619, 5.024999185517319], [3.1542441151785208, 5.204696355131997], [3.658408764046296, 4.611626765508735], [3.3619284175956508, 5.0769972783189035], [3.596483291054488, 5.052226481991641], [2.9701097616320284, 5.531682243130713], [2.731096182040875, 4.745566004089044], [2.9982944633987256, 5.714256270854997], [3.1948091030692796, 6.070899492245685], [3.392895177777541, 4.2886647074932345], [4.332973785345426, 5.53678658538905], [3.1821907341696787, 5.6621112375151235]]
)
save({'qsvm_results': qsvm_results})
```
qfunc main(data1: real[2], data2: real[2], output qba: qnum) {
allocate(ceiling(data1.len / 2), qba);
bloch_feature_map(data1, qba);
invert {
bloch_feature_map(data2, qba);
}
}
45 changes: 44 additions & 1 deletion algorithms/qml/qsvm/qsvm.synthesis_options.json
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{}
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"machine_precision": 8,
"custom_hardware_settings": {
"basis_gates": [
"h",
"ry",
"sxdg",
"u2",
"cy",
"sdg",
"u",
"u1",
"p",
"cx",
"cz",
"sx",
"y",
"rx",
"t",
"x",
"tdg",
"z",
"r",
"rz",
"id",
"s"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"synthesize_all_separately": false,
"optimization_level": 3,
"output_format": ["qasm"],
"pretty_qasm": true,
"transpilation_option": "auto optimize",
"timeout_seconds": 300,
"random_seed": 3405390845
}
}
440 changes: 350 additions & 90 deletions algorithms/qml/qsvm_pauli_feature_map/qsvm_pauli_feature_map.ipynb

Large diffs are not rendered by default.

67 changes: 45 additions & 22 deletions algorithms/qml/qsvm_pauli_feature_map/qsvm_pauli_feature_map.qmod
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
qfunc main(output qbv: qbit[]) {
allocate(2, qbv);
pauli_feature_map(QSVMFeatureMapPauli {
paulis=[
[Pauli::Z],
[Pauli::Z, Pauli::Z]
],
entanglement=QSVMFeatureMapEntanglement::CIRCULAR,
alpha=2,
reps=2,
feature_dimension=2
}, qbv);
qfunc pauli_kernel_expanded___0(qba: qbit[2]) {
power (2) {
hadamard_transform(qba);
suzuki_trotter([
PauliTerm {
pauli=[3, 0],
coefficient=data1_param_0
},
PauliTerm {
pauli=[0, 3],
coefficient=data1_param_1
},
PauliTerm {
pauli=[3, 3],
coefficient=(data1_param_0 - 3.1416) * (data1_param_1 - 3.1416)
}
], -1, 1, 1, qba);
}
}

cscope ```
qsvm_results = qsvm_full_run(
train_data=[[2.0734511513692637, 5.843362335677016], [4.0212385965949355, 4.523893421169302], [1.9477874452256718, 1.6964600329384885], [3.9584067435231396, 2.8274333882308142], [4.272566008882119, 5.6548667764616285], [2.1362830044410597, 1.7592918860102844], [3.832743037379548, 0.3769911184307752], [2.450442269800039, 1.884955592153876], [5.969026041820608, 2.7646015351590183], [5.026548245743669, 1.3194689145077132], [4.775220833456486, 2.9530970943744057], [6.157521601035995, 1.6964600329384885], [4.1469023027385274, 1.6336281798666925], [5.215043804959057, 3.0159289474462017], [3.769911184307752, 3.0787608005179976], [3.769911184307752, 5.215043804959057], [2.324778563656447, 3.832743037379548], [5.089380098815465, 1.2566370614359172], [2.0734511513692637, 1.5079644737231008], [2.1362830044410597, 0.5026548245743669], [2.9530970943744057, 1.2566370614359172], [0.3769911184307752, 2.0734511513692637], [6.031857894892403, 5.717698629533424], [5.026548245743669, 0.7539822368615504], [4.900884539600078, 2.324778563656447], [1.6336281798666925, 6.031857894892403], [5.906194188748811, 4.39822971502571], [0.12566370614359174, 2.1362830044410597], [0.6911503837897546, 4.39822971502571], [3.0787608005179976, 4.586725274241099], [5.215043804959057, 4.71238898038469], [1.6964600329384885, 3.832743037379548], [0.25132741228718347, 1.9477874452256718], [3.204424506661589, 5.46637121724624], [4.71238898038469, 0.7539822368615504], [4.775220833456486, 0.8796459430051422], [3.1415926535897936, 2.6389378290154264], [5.026548245743669, 2.5761059759436304], [5.46637121724624, 6.157521601035995], [4.9637163926718735, 0.25132741228718347]],
train_labels=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
test_data=[[2.6389378290154264, 3.832743037379548], [4.838052686528282, 3.330088212805181], [6.031857894892403, 1.5079644737231008], [4.335397861953915, 2.6389378290154264], [4.272566008882119, 1.0681415022205298], [0.12566370614359174, 2.1362830044410597], [4.9637163926718735, 0.1884955592153876], [3.455751918948773, 4.335397861953915], [2.8902652413026098, 2.450442269800039], [6.220353454107791, 5.403539364174445]],
test_labels=[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
predict_data=[[1.8221237390820801, 1.3194689145077132], [3.8955748904513436, 2.7646015351590183], [3.6442474781641603, 2.324778563656447], [0.942477796076938, 0.3141592653589793], [2.5761059759436304, 1.0053096491487339], [4.586725274241099, 2.324778563656447], [1.6964600329384885, 3.769911184307752], [3.0787608005179976, 1.7592918860102844], [6.031857894892403, 5.277875658030853], [5.906194188748811, 4.209734155810323]]
)
save({'qsvm_results': qsvm_results})
```
qfunc pauli_kernel_expanded___1(qba: qbit[2]) {
power (2) {
hadamard_transform(qba);
suzuki_trotter([
PauliTerm {
pauli=[3, 0],
coefficient=data2_param_0
},
PauliTerm {
pauli=[0, 3],
coefficient=data2_param_1
},
PauliTerm {
pauli=[3, 3],
coefficient=(data2_param_0 - 3.1416) * (data2_param_1 - 3.1416)
}
], -1, 1, 1, qba);
}
}

qfunc main(output qba: qnum<2, False, 0>) {
allocate(2, qba);
pauli_kernel_expanded___0(qba);
invert {
pauli_kernel_expanded___1(qba);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
{}
{
"constraints": {
"max_gate_count": {},
"optimization_parameter": "no_opt"
},
"preferences": {
"machine_precision": 8,
"custom_hardware_settings": {
"basis_gates": [
"p",
"id",
"t",
"u1",
"u",
"rx",
"cy",
"x",
"sdg",
"sxdg",
"cx",
"cz",
"u2",
"h",
"rz",
"ry",
"r",
"y",
"sx",
"z",
"s",
"tdg"
],
"is_symmetric_connectivity": true
},
"debug_mode": true,
"synthesize_all_separately": false,
"optimization_level": 3,
"output_format": ["qasm"],
"pretty_qasm": true,
"transpilation_option": "auto optimize",
"timeout_seconds": 300,
"random_seed": 3398128133
}
}
622 changes: 362 additions & 260 deletions applications/finance/credit_card_fraud/credit_card_fraud.ipynb

Large diffs are not rendered by default.

Loading
Loading