diff --git a/lib/quantum-circuit.js b/lib/quantum-circuit.js index 9fb014f..7c6b777 100644 --- a/lib/quantum-circuit.js +++ b/lib/quantum-circuit.js @@ -152,6 +152,45 @@ var QuantumCircuit = function(numQubits) { } }, + u0: { + description: "Single qubit idle (identity) gate", + matrix: [ + [1, 0], + [0, 1] + ], + params: [], + drawingInfo: { + connectors: ["box"], + label: "ID" + }, + exportInfo: { + quil: { + name: "I" + }, + cirq: { + name: "I", + notTfqSupported: true + }, + quest: { + name: "compactUnitary", + params: { alpha: "(Complex) { .real = 1, .imag = 0 }", + beta: "(Complex) {.real = 0, .imag = 0}"} + }, + qsharp: { + name: "I" + }, + qiskit: { + name: "iden" + }, + braket: { + name: "i" + }, + aqasm: { + name: "I" + } + } + }, + x: { description: "Pauli X (PI rotation over X-axis) aka \"NOT\" gate", matrix: [ @@ -340,6 +379,47 @@ var QuantumCircuit = function(numQubits) { } }, + sx: { + description: "Square root of X", + matrix: [ + ["0.5+0.5i","0.5-0.5i"], + ["0.5-0.5i","0.5+0.5i"] + ], + params: [], + drawingInfo: { + connectors: ["box"], + label: "√X" + }, + exportInfo: { + quil: { + name: "srn", + defgate: "DEFGATE srn:\n 0.5+0.5i, 0.5-0.5i\n 0.5-0.5i, 0.5+0.5i" + }, + pyquil: { + name: "srn", + array: "[[0.5+0.5j, 0.5-0.5j], [0.5-0.5j, 0.5+0.5j]]" + }, + cirq: { + name: "X**(1/2)" + }, + quest: { + name: "unitary", + matrix: [[["0.5", "0.5"], ["0.5", "-0.5"]], + [["0.5", "-0.5"],["0.5", "0.5"]]] + }, + qiskit: { + name: "sx" + }, + braket: { + name: "v" + }, + aqasm: { + matrix: [["0.5+0.5i","0.5-0.5i"],["0.5-0.5i","0.5+0.5i"]], + array: "[[0.5+0.5j, 0.5-0.5j], [0.5-0.5j, 0.5+0.5j]]" + } + } + }, + srndg: { description: "Inverse square root of NOT", matrix: [ @@ -384,6 +464,47 @@ var QuantumCircuit = function(numQubits) { } }, + sxdg: { + description: "Inverse square root of NOT", + matrix: [ + ["0.5-0.5i","0.5+0.5i"], + ["0.5+0.5i","0.5-0.5i"] + ], + params: [], + drawingInfo: { + connectors: ["box"], + label: "√X†" + }, + exportInfo: { + quil: { + name: "srndg", + defgate: "DEFGATE srndg:\n 0.5-0.5i, 0.5+0.5i\n 0.5+0.5i, 0.5-0.5i" + }, + pyquil: { + name: "srndg", + array: "[[0.5-0.5j, 0.5+0.5j], [0.5+0.5j, 0.5-0.5j]]" + }, + cirq: { + name: "X**(-1/2)" + }, + quest: { + name: "unitary", + matrix: [[["0.5", "-0.5"], ["0.5", "0.5"]], + [["0.5", "0.5"],["0.5", "-0.5"]]] + }, + qiskit: { + name: "sxdg" + }, + braket: { + name: "vi" + }, + aqasm: { + matrix: [["0.5-0.5i","0.5+0.5i"],["0.5+0.5i","0.5-0.5i"]], + array: "[[0.5-0.5j, 0.5+0.5j], [0.5+0.5j, 0.5-0.5j]]" + } + } + }, + r2: { description: "PI/2 rotation over Z-axis aka \"Phase PI/2\"", matrix: [ @@ -701,6 +822,42 @@ var QuantumCircuit = function(numQubits) { } }, + p: { + description: "Phase Gate", + matrix: [ + [1,0], + [0,"exp(i * lambda)"] + ], + params: ["lambda"], + drawingInfo: { + connectors: ["box"], + label: "P" + }, + exportInfo: { + quil: { + name: "PHASE", + params: ["lambda"] + }, + cirq: { + name: "p", + params: ["lambda"], + array: "[[1, 0], [0, np.exp(1j*p_lambda)]]", + notTfqSupported: true + }, + quest: { + name: "phaseShift", + params: ["lambda"] + }, + braket: { + name: "phaseshift", + params: ["lambda"] + }, + aqasm: { + name: "PH" + } + } + }, + u2: { description: "Single-qubit rotation about the X+Z axis", matrix: [ @@ -795,6 +952,53 @@ var QuantumCircuit = function(numQubits) { } }, + u: { + description: "Generic single-qubit rotation gate with 3 Euler angles", + matrix: [ + [ "cos(theta/2)", "-exp(i * lambda) * sin(theta / 2)" ], + [ "exp(i * phi) * sin(theta / 2)", "exp(i * lambda + i * phi) * cos(theta / 2)" ] + ], + params: ["theta", "phi", "lambda"], + drawingInfo: { + connectors: ["box"], + label: "U" + }, + exportInfo: { + quil: { + name: "u", + params: ["theta", "phi", "lambda"], + defgate: "DEFGATE u3(%theta, %phi, %lambda):\n COS(%theta/2), -1*EXP(i*%lambda)*SIN(%theta/2)\n EXP(i*%phi)*SIN(%theta/2), EXP(i*%lambda + i*%phi)*COS(%theta/2)" + }, + pyquil: { + name: "u", + params: ["theta", "phi", "lambda"], + array: "[[quil_cos(p_theta/2),-quil_exp(1j*p_lambda)*quil_sin(p_theta/2)],[quil_exp(1j*p_phi)*quil_sin(p_theta/2),quil_exp(1j*p_lambda+1j*p_phi)*quil_cos(p_theta/2)]]" + }, + cirq: { + name: "u", + params: ["theta", "phi", "lambda"], + array: "[[np.cos(p_theta/2), -np.exp(1j*p_lambda)*np.sin(p_theta/2)], [np.exp(1j*p_phi)*np.sin(p_theta/2), np.exp(1j*p_lambda+1j*p_phi)*np.cos(p_theta/2)]]", + notTfqSupported: true + }, + quest: { + name: "unitary", + params: ["theta", "phi", "lambda"], + matrix: [[["cos(theta/2)", "0"], ["-cos(lambda)*sin(theta/2)", "-sin(lambda)*sin(theta/2)"]], + [["cos(phi)*sin(theta/2)", "sin(phi)*sin(theta/2)"], ["cos(lambda+phi)*cos(theta/2)", "sin(lambda+phi)*cos(theta/2)"]]] + }, + braket: { + name: "unitary", + params: ["theta", "phi", "lambda"], + array: "[[np.cos(p_theta/2), -np.exp(1j*p_lambda)*np.sin(p_theta/2)], [np.exp(1j*p_phi)*np.sin(p_theta/2), np.exp(1j*p_lambda+1j*p_phi)*np.cos(p_theta/2)]]" + }, + aqasm: { + matrix: [[ "cos(theta/2)", "-exp(i * lambda) * sin(theta / 2)" ],[ "exp(i * phi) * sin(theta / 2)", "exp(i * lambda + i * phi) * cos(theta / 2)" ]], + array: "[[np.cos(p_theta/2), -np.exp(1j*p_lambda)*np.sin(p_theta/2)], [np.exp(1j*p_phi)*np.sin(p_theta/2), np.exp(1j*p_lambda+1j*p_phi)*np.cos(p_theta/2)]]", + params: ["theta", "phi", "lambda"] + } + } + }, + s: { description: "PI/2 rotation over Z-axis (synonym for `r2`)", matrix: [ @@ -1469,6 +1673,58 @@ var QuantumCircuit = function(numQubits) { } }, + csx: { + description: "Controlled square root of NOT", + matrix: [ + [1,0,0,0], + [0,1,0,0], + [0,0,"0.5+0.5i","0.5-0.5i"], + [0,0,"0.5-0.5i","0.5+0.5i"] + ], + params: [], + drawingInfo: { + connectors: ["dot","box"], + label: "√X", + root: "sx" + }, + exportInfo: { + quest: { + name: "controlledUnitary", + matrix: [[["-1/sqrt(2)", "0"], ["-1/sqrt(2)", "0"]], + [["-1/sqrt(2)", "0"], ["1/sqrt(2)", "0"]]] + }, + cirq: { + replacement: { + name: "srn", + type: "controlled", + notTfqSupported: true + } + }, + quil: { + name: "csx", + defgate: "DEFGATE csrn:\n 1, 0, 0, 0\n 0, 1, 0, 0\n 0, 0, 0.5+0.5i, 0.5-0.5i\n 0, 0, 0.5-0.5i, 0.5+0.5i" + }, + qasm: { + name: "csx" + }, + qiskit: { + name: "csx" + }, + pyquil: { + name: "csx", + array: "[[1,0,0,0],[0,1,0,0],[0,0,0.5+0.5j,0.5-0.5j],[0,0,0.5-0.5j,0.5+0.5j]]" + }, + braket: { + name: "unitary", + array: "[[1,0,0,0],[0,1,0,0],[0,0,0.5+0.5j,0.5-0.5j],[0,0,0.5-0.5j,0.5+0.5j]]" + }, + aqasm: { + matrix: [[1,0,0,0],[0,1,0,0],[0,0,"0.5+0.5i","0.5-0.5i"],[0,0,"0.5-0.5i","0.5+0.5i"]], + array: "[[1,0,0,0],[0,1,0,0],[0,0,0.5+0.5j,0.5-0.5j],[0,0,0.5-0.5j,0.5+0.5j]]" + } + } + }, + ms: { description: "Mølmer-Sørensen gate", matrix: [ @@ -1609,6 +1865,56 @@ var QuantumCircuit = function(numQubits) { } }, + rxx: { + description: "Parametric 2-qubit rotation about XX", + matrix: [ + [ "cos(theta / 2)", 0, 0, "-i*sin(theta/2)" ], + [ 0, "cos(theta / 2)", "-i*sin(theta/2)", 0 ], + [ 0, "-i*sin(theta/2)", "cos(theta / 2)", 0 ], + [ "-i*sin(theta/2)", 0, 0, "cos(theta / 2)" ] + ], + params: ["theta"], + drawingInfo: { + connectors: ["circle","circle"], + label: "RXX" + }, + exportInfo: { + qiskit: { + name: "rxx" + } + } + }, + + rzz: { + description: "Parametric 2-qubit rotation about ZZ", + matrix: [ + [ "exp(-i * theta / 2)", 0, 0, 0 ], + [ 0, "exp(i * theta / 2)", 0, 0 ], + [ 0, 0, "exp(i * theta / 2)", 0 ], + [ 0, 0, 0, "exp(-i * theta / 2)" ] + ], + params: ["theta"], + drawingInfo: { + connectors: ["circle","circle"], + label: "RZZ" + }, + exportInfo: { + quil: { + name: "rzz", + params: ["theta"], + defgate: "DEFGATE zz(%theta):\n EXP(-i * %theta / 2), 0, 0, 0\n 0, EXP(i * %theta / 2), 0, 0\n 0, 0, EXP(i * %theta / 2), 0\n 0, 0, 0, EXP(-i * %theta / 2)" + }, + pyquil: { + name: "rzz", + params: ["theta"], + array: "[ [ quil_exp(-1j * p_theta / 2), 0, 0, 0 ], [ 0, quil_exp(1j * p_theta / 2), 0, 0], [ 0, 0, quil_exp(1j * p_theta / 2), 0 ], [ 0, 0, 0, quil_exp(-1j * p_theta / 2) ] ]" + }, + qiskit: { + name: "rzz" + } + } + }, + cr2: { description: "Controlled PI/2 rotation over Z-axis", matrix: [ @@ -2001,6 +2307,28 @@ var QuantumCircuit = function(numQubits) { } }, + cu: { + description: "Controlled U gate", + matrix: + [ + [1,0,0,0], + [0,1,0,0], + [ 0, 0, "cos(theta/2)", "-exp(i * lambda) * sin(theta / 2)" ], + [ 0,0,0,"exp(i * phi) * sin(theta / 2)", "exp(i * lambda + i * phi) * cos(theta / 2)" ] + ], + params: ["theta","phi","lambda","gamma"], + drawingInfo: { + connectors: ["dot","box"], + label: "CU", + root: "u" + }, + exportInfo: { + qiskit: { + name: "cu" + } + } + }, + cu1: { description: "Controlled rotation about the Z axis", matrix: [ @@ -2042,6 +2370,47 @@ var QuantumCircuit = function(numQubits) { } }, + cp: { + description: "Controlled rotation about the Z axis", + matrix: [ + [1,0,0,0], + [0,1,0,0], + [0,0,1,0], + [0,0,0,"exp(i * lambda)"] + ], + params: ["lambda"], + drawingInfo: { + connectors: ["dot","box"], + label: "CP", + root: "p" + }, + exportInfo: { + quil: { + name: "CPHASE", + params: ["lambda"] + }, + cirq: { + name: "cp", + params: ["lambda"], + array: "[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, np.exp(1j*p_lambda)]]", + notTfqSupported: true + }, + quest: { + name: "controlledPhaseShift", + params: ["theta"] + }, + braket: { + name: "unitary", + params: ["lambda"], + array: "[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, np.exp(1j*p_lambda)]]" + }, + aqasm: { + name: "PH", + controlled: true + } + } + }, + cu2: { description: "Controlled rotation about the X+Z axis", matrix: [ @@ -2488,6 +2857,31 @@ var QuantumCircuit = function(numQubits) { } }, + rccx: { + description: "Relative Phase \"CCNOT\" gate", + matrix: [ + [1,0,0,0,0,0,0,0], + [0,1,0,0,0,0,0,0], + [0,0,1,0,0,0,0,0], + [0,0,0,0,0,0,0,"-i"], + [0,0,0,0,1,0,0,0], + [0,0,0,0,0,-1,0,0], + [0,0,0,0,0,0,1,0], + [0,0,0,"i",0,0,0,0] + ], + params: [], + drawingInfo: { + connectors: ["dot","dot","not"], + label: "RCCX", + root: "ccx" + }, + exportInfo: { + qiskit: { + name: "rccx" + } + } + }, + cswap: { description: "Controlled swap aka \"Fredkin\" gate", matrix: [ @@ -2605,6 +2999,177 @@ var QuantumCircuit = function(numQubits) { } }, + rc3x: { + description: "Relative Phase 3-Controlled X gate", + matrix: [ + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,"i",0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], + [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,"-i",0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0], + [0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0] + ], + params: [], + drawingInfo: { + connectors: ["dot","dot","not"], + label: "RC3X", + root: "c3x" + }, + exportInfo: { + qiskit: { + name: "RC3XGate()", + class: true + } + } + }, + + c3x: { + description: "3-Controlled X gate", + matrix: [ + [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], + [0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0], + [0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0] + ], + params: [], + drawingInfo: { + connectors: ["dot","dot","not"], + label: "C3X", + root: "c3x" + }, + exportInfo: { + qiskit: { + name: "C3XGate()", + class: true + } + } + }, + + c3sqrtx: { + description: "3-Controlled SQRT(X) gate", + matrix: [ + [1,0,0,0,0,0,0,0], + [0,1,0,0,0,0,0,0], + [0,0,1,0,0,0,0,0], + [0,0,0,1,0,0,0,0], + [0,0,0,0,1,0,0,0], + [0,0,0,0,0,1,0,0], + [0,0,0,0,0,0,0,1], + [0,0,0,0,0,0,1,0] + ], + params: [], + drawingInfo: { + connectors: ["dot","dot","not"], + label: "C3XSQRTX", + root: "c3x" + }, + exportInfo: { + qiskit: { + equivalent: [ + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "-1*pi/8" }, wires: [0, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [0, 1] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "pi/8" }, wires: [1, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [0, 1] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "-1*pi/8" }, wires: [1, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [1, 2] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "pi/8" }, wires: [2, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [0, 2] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "-1*pi/8" }, wires: [2, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [1, 2] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "pi/8" }, wires: [2, 3] }, + { name: "h", wires: [3] }, + { name: "cx", wires: [0, 2] }, + { name: "h", wires: [3] }, + { name: "cu1", params: { lambda: "-1*pi/8" }, wires: [2, 3] }, + { name: "h", wires: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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + ], + params: [], + drawingInfo: { + connectors: ["dot","dot","dot","dot","not"], + label: "C4X", + root: "c3x" + }, + exportInfo: { + qiskit: { + name: "C4XGate()", + class: true + } + } + }, + reset: { description: "Resets qubit", matrix: [], @@ -7325,6 +7890,7 @@ QuantumCircuit.prototype.exportToQiskit = function(options, exportAsGateName, ci if(!circuitReplacement) { qiskit += "from qiskit import QuantumRegister, ClassicalRegister\n"; qiskit += "from qiskit import QuantumCircuit, execute, " + providerName + "\n"; + qiskit += "from qiskit.circuit.library import *\n"; if(hybrid) { qiskit += "from scipy.optimize import minimize\n"; @@ -7449,7 +8015,15 @@ QuantumCircuit.prototype.exportToQiskit = function(options, exportAsGateName, ci qiskitEquivalent = gateDef.exportInfo.qiskit.equivalent; qiskitEquivalent.map(function(equivalent){ var equivalentCircuit = new QuantumCircuit(); - var gateWires = equivalent.wires.length > 1 ? gate.wires : gate.wires[equivalent.wires[0]]; + var gateWires = []; + if(equivalent.wires.length > 1){ + equivalent.wires.map(function(eWire){ + gateWires.push(gate.wires[eWire]); + }) + }else { + gateWires = gate.wires[equivalent.wires[0]]; + } + var eqParams = {}; if(equivalent.params) { var gateParams = {}; @@ -7464,6 +8038,7 @@ QuantumCircuit.prototype.exportToQiskit = function(options, exportAsGateName, ci } } + equivalentCircuit.addGate(equivalent.name, column, gateWires, { params: eqParams, condition: qiskitCondition }); var newOptions = { comment: "", @@ -7498,12 +8073,21 @@ QuantumCircuit.prototype.exportToQiskit = function(options, exportAsGateName, ci } if(gateDef && gateDef.exportInfo && gateDef.exportInfo.qiskit && gateDef.exportInfo.qiskit.name){ + if(gateDef.exportInfo.qiskit.class){ + qiskit += "append(" + } gateName = gateDef.exportInfo.qiskit.name; }else{ gateName = gate.name; } - qiskit += gateName + "("; + qiskit += gateName; + + if(gateDef && gateDef.exportInfo && gateDef.exportInfo.qiskit && gateDef.exportInfo.qiskit.class){ + qiskit += ", [" + }else { + qiskit += "(" + } var argCount = 0; if(gateParams) { @@ -7560,6 +8144,10 @@ QuantumCircuit.prototype.exportToQiskit = function(options, exportAsGateName, ci argCount++; } + if(gateDef && gateDef.exportInfo && gateDef.exportInfo.qiskit && gateDef.exportInfo.qiskit.class){ + qiskit += "]" + } + qiskit += ")"; if(gate.options && gate.options.condition && gate.options.condition.creg) {