Skip to content

Commit bfc5c0e

Browse files
committed
Fixed bug with exporting synonime named gates to qasm and qiskit and enabled import by synonyme
1 parent b2a5a33 commit bfc5c0e

File tree

2 files changed

+49
-38
lines changed

2 files changed

+49
-38
lines changed

lib/qasm_import/QASMImport.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,22 @@ QCQASMListener.prototype.enterQop = function(ctx) {
366366
var mixedlist = uop.anylist() ? uop.anylist().mixedlist() : null;
367367
var explist = uop.explist();
368368

369+
switch(gateName) {
370+
case "CX": gateName = "cx"; break;
371+
case "U": gateName = "u3"; break;
372+
}
373+
374+
if(!self.circuit.basicGates[gateName] && !self.circuit.customGates[gateName]) {
375+
// find gate by qasm name
376+
for(var tmpName in self.circuit.basicGates) {
377+
var tmpDef = self.circuit.basicGates[tmpName];
378+
if(tmpDef.exportInfo && tmpDef.exportInfo.qasm && tmpDef.exportInfo.qasm.name && tmpDef.exportInfo.qasm.name == gateName) {
379+
gateName = tmpName;
380+
break;
381+
}
382+
}
383+
}
384+
369385
var params = {};
370386
if(explist && explist.exp()) {
371387
var gateDef = self.circuit.basicGates[gateName];
@@ -405,11 +421,6 @@ QCQASMListener.prototype.enterQop = function(ctx) {
405421
wires.push(a.bit + self.qregBase(a.reg));
406422
});
407423

408-
switch(gateName) {
409-
case "CX": gateName = "cx"; break;
410-
case "U": gateName = "u3"; break;
411-
}
412-
413424
if(!self.compatibilityMode) {
414425
switch(gateName) {
415426
case "rz": {
@@ -448,11 +459,6 @@ QCQASMListener.prototype.enterQop = function(ctx) {
448459
wires.push(a.bit + self.qregBase(a.reg));
449460
});
450461

451-
switch(gateName) {
452-
case "CX": gateName = "cx"; break;
453-
case "U": gateName = "u3"; break;
454-
}
455-
456462
if(!self.compatibilityMode) {
457463
switch(gateName) {
458464
case "rz": {
@@ -465,6 +471,7 @@ QCQASMListener.prototype.enterQop = function(ctx) {
465471
}
466472
}
467473

474+
console.log(gateName, wires, options);
468475
self.circuit.addGate(gateName, -1, wires, options);
469476
}
470477
}

lib/quantum-circuit.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ var QuantumCircuit = function(numQubits) {
14391439
params: ["theta"],
14401440
drawingInfo: {
14411441
connectors: ["circle","circle"],
1442-
label: "X"
1442+
label: "XX"
14431443
},
14441444
exportInfo: {
14451445
quil: {
@@ -1460,6 +1460,9 @@ var QuantumCircuit = function(numQubits) {
14601460
//@TODO add function
14611461
func: "TODO"
14621462
},
1463+
qasm: {
1464+
name: "rxx"
1465+
},
14631466
qiskit: {
14641467
name: "rxx"
14651468
},
@@ -1490,7 +1493,7 @@ var QuantumCircuit = function(numQubits) {
14901493
params: ["theta"],
14911494
drawingInfo: {
14921495
connectors: ["circle","circle"],
1493-
label: "Y"
1496+
label: "YY"
14941497
},
14951498
exportInfo: {
14961499
quil: {
@@ -1519,31 +1522,39 @@ var QuantumCircuit = function(numQubits) {
15191522
matrix: [["cos(theta)", 0, 0, "i*sin(theta)"],[0, "cos(theta)", "-i*sin(theta)", 0],[0, "-i*sin(theta)", "cos(theta)", 0],["i*sin(theta)", 0, 0, "cos(theta)"]],
15201523
array: "[[np.cos(p_theta), 0, 0, 1j*np.sin(p_theta)], [0, np.cos(p_theta), -1j*np.sin(p_theta), 0], [0, -1j*np.sin(p_theta), np.cos(p_theta), 0], [1j*np.sin(p_theta), 0, 0, np.cos(p_theta)] ]",
15211524
params: ["theta"]
1525+
},
1526+
qasm: {
1527+
name: "ryy"
1528+
},
1529+
qiskit: {
1530+
name: "ryy"
15221531
}
15231532
}
15241533
},
1525-
/*
1526-
xx: {
1527-
description: "Ising (XX) gate",
1528-
matrix: [
1529-
["1/sqrt(2)", 0, 0, "1/sqrt(2) * (-i * pow(e, i * phi))"],
1530-
1531-
[0, "1/sqrt(2)", "-i", 0],
15321534

1533-
[0, "-i", "1/sqrt(2)", 0],
1534-
1535-
["1/sqrt(2) * (-i * pow(e, -i * phi))", 0, 0, "1/sqrt(2)"]
1535+
zz: {
1536+
description: "Parametrix 2-qubit rotation about ZZ",
1537+
matrix: [
1538+
[ "exp(-i * theta / 2)", 0, 0, 0 ],
1539+
[ 0, "exp(i * theta / 2)", 0, 0 ],
1540+
[ 0, 0, "exp(i * theta / 2)", 0 ],
1541+
[ 0, 0, 0, "exp(-i * theta / 2)" ]
15361542
],
1537-
params: ["phi"],
1543+
params: ["theta"],
15381544
drawingInfo: {
1539-
connectors: ["not","not"],
1540-
label: "XX"
1545+
connectors: ["circle","circle"],
1546+
label: "ZZ"
15411547
},
15421548
exportInfo: {
1543-
1549+
qasm: {
1550+
name: "rzz"
1551+
},
1552+
qiskit: {
1553+
name: "rzz"
1554+
}
15441555
}
15451556
},
1546-
*/
1557+
15471558
cr2: {
15481559
description: "Controlled PI/2 rotation over Z-axis",
15491560
matrix: [
@@ -6892,14 +6903,6 @@ QuantumCircuit.prototype.exportToSVG = function(options) {
68926903
if(connector == "x") {
68936904
connector = "box";
68946905
}
6895-
6896-
if(gateName == "ms") {
6897-
gateLabel = "XX";
6898-
}
6899-
6900-
if(gateName == "yy") {
6901-
gateLabel = "YY";
6902-
}
69036906
}
69046907

69056908
var uniqStr = gateLabel + "|" + connector;
@@ -8024,10 +8027,11 @@ QuantumCircuit.prototype.exportToQASM = function(options, exportAsGateName, circ
80248027
}
80258028

80268029
if((!qasmReplacement && !qasmEquivalent) || compatibilityMode) {
8027-
var gateName = compatibilityMode ? gate.name : qasmName;
8028-
8030+
var gateName = gate.name;
80298031
var gateParams = gate.options && gate.options.params ? gate.options.params : {};
8030-
qasm += gateName;
8032+
8033+
qasm += compatibilityMode ? gate.name : qasmName;
8034+
80318035
if(gateParams) {
80328036
var gateDef = this.basicGates[gateName];
80338037
if(!gateDef) {

0 commit comments

Comments
 (0)