@@ -4314,6 +4314,13 @@ QuantumCircuit.prototype.convertToCustomGate = function(gateName, decompose, add
43144314 this . cregs = { } ;
43154315
43164316 var source = this . save ( decompose ) ;
4317+ if ( source . options ) {
4318+ source . options . hybrid = false ;
4319+ if ( source . options . hybridOptions ) {
4320+ delete source . options . hybridOptions ;
4321+ }
4322+ }
4323+
43174324 this . clear ( ) ;
43184325 this . customGates [ gateName ] = source ;
43194326
@@ -6115,7 +6122,7 @@ QuantumCircuit.prototype.exportSVG = function(embedded, options) {
61156122 var newOptions = options || { } ;
61166123 newOptions . embedded = ! ! embedded ;
61176124
6118- return exportToSVG ( newOptions ) ;
6125+ return this . exportToSVG ( newOptions ) ;
61196126} ;
61206127
61216128QuantumCircuit . prototype . exportToSVG = function ( options ) {
@@ -8950,9 +8957,17 @@ QuantumCircuit.prototype.exportToQuil = function(options, exportAsGateName) {
89508957 return quil ;
89518958} ;
89528959
8953- QuantumCircuit . prototype . exportAQASM = function ( comment , decompose , isExportPyAQASM , exportAsGateName , asJupyter , shots , hybrid , indentDepth ) {
8960+ QuantumCircuit . prototype . exportToAQASM = function ( options , isExportPyAQASM , exportAsGateName , indentDepth ) {
89548961 var self = this ;
89558962
8963+ options = options || { } ;
8964+
8965+ var comment = options . comment ;
8966+ var decompose = options . decompose ;
8967+ var asJupyter = options . asJupyter ;
8968+ var shots = options . shots ;
8969+ var hybrid = ! ! isExportPyAQASM ? options . hybrid : false ;
8970+
89568971 var circuit = null ;
89578972
89588973 shots = shots || 1024 ;
@@ -9027,7 +9042,7 @@ QuantumCircuit.prototype.exportAQASM = function(comment, decompose, isExportPyAQ
90279042
90289043 if ( ! isExportPyAQASM ) {
90299044 aqasm += indent + "BEGIN\n" ;
9030- aqasm += indent + "qubits " + numQubits ;
9045+ aqasm += indent + "qubits " + numQubits + "\n" ;
90319046 } else {
90329047 if ( exportAsGateName ) {
90339048 var args = "" ;
@@ -9106,7 +9121,16 @@ QuantumCircuit.prototype.exportAQASM = function(comment, decompose, isExportPyAQ
91069121 if ( customGate ) {
91079122 var customCircuit = new QuantumCircuit ( ) ;
91089123 customCircuit . load ( customGate ) ;
9109- aqasm += customCircuit . exportAQASM ( "" , true , true , usedGateName , false , null , false , indentDepth ) ;
9124+
9125+ var newOptions = {
9126+ comment : "" ,
9127+ decompose : true ,
9128+ asJupyter : false ,
9129+ shots : null ,
9130+ hybrid : false
9131+ } ;
9132+
9133+ aqasm += customCircuit . exportAQASM ( newOptions , isExportPyAQASM , usedGateName , indentDepth ) ;
91109134 submoduleCount ++ ;
91119135 }
91129136 }
@@ -9306,13 +9330,13 @@ QuantumCircuit.prototype.exportAQASM = function(comment, decompose, isExportPyAQ
93069330 }
93079331 }
93089332
9309- if ( exportAsGateName ) {
9333+ if ( exportAsGateName ) {
93109334 aqasm += indent + "return circuit\n\n" ;
93119335 }
93129336
9313- if ( ! isExportPyAQASM ) {
9337+ if ( ! isExportPyAQASM ) {
93149338 aqasm += "END" ;
9315- } else {
9339+ } else {
93169340 if ( ! exportAsGateName ) {
93179341 aqasm += indent + "\n" ;
93189342 aqasm += indent + "circuit = program.to_circ()\n" ;
@@ -9364,14 +9388,63 @@ QuantumCircuit.prototype.exportAQASM = function(comment, decompose, isExportPyAQ
93649388 }
93659389 }
93669390 }
9391+
9392+ if ( asJupyter && isExportPyAQASM ) {
9393+ var notebook = {
9394+ metadata : {
9395+ kernelspec : {
9396+ display_name : "Python 3" ,
9397+ language : "python" ,
9398+ name : "python3"
9399+ }
9400+ } ,
9401+ nbformat : 4 ,
9402+ nbformat_minor : 0 ,
9403+ cells : [
9404+ {
9405+ cell_type : "code" ,
9406+ source : aqasm ,
9407+ metadata : {
9408+
9409+ } ,
9410+ outputs : [ ] ,
9411+ execution_count : null
9412+ }
9413+ ]
9414+ } ;
9415+ return JSON . stringify ( notebook ) ;
9416+ }
9417+
93679418 return aqasm
93689419} ;
93699420
9370- QuantumCircuit . prototype . exportPyAQASM = function ( comment , decompose , exportAsGateName , asJupyter , shots , hybrid ) {
9421+ QuantumCircuit . prototype . exportAQASM = function ( comment , decompose , isExportPyAQASM , exportAsGateName , asJupyter , shots , hybrid , indentDepth ) {
9422+ var options = {
9423+ comment : comment ,
9424+ decompose : decompose ,
9425+ asJupyter : asJupyter ,
9426+ shots : shots ,
9427+ hybrid : hybrid
9428+ } ;
9429+
9430+ return this . exportToAQASM ( options , isExportPyAQASM , exportAsGateName , indentDepth ) ;
9431+ } ;
9432+
93719433
9372- return this . exportAQASM ( comment , decompose , true , exportAsGateName , asJupyter , shots , hybrid ) ;
9434+ QuantumCircuit . prototype . exportToPyAQASM = function ( options , exportAsGateName ) {
9435+ return this . exportToAQASM ( options , true , exportAsGateName ) ;
93739436} ;
93749437
9438+ QuantumCircuit . prototype . exportPyAQASM = function ( comment , decompose , exportAsGateName , asJupyter , shots , hybrid ) {
9439+ var options = {
9440+ comment : comment ,
9441+ decompose : decompose ,
9442+ asJupyter : asJupyter ,
9443+ shots : shots ,
9444+ hybrid : hybrid
9445+ } ;
9446+ return this . exportToPyAQASM ( options , exportAsGateName ) ;
9447+ } ;
93759448
93769449QuantumCircuit . prototype . exportToCirq = function ( options , exportAsGateName ) {
93779450 options = options || { } ;
0 commit comments