diff --git a/examples/adder.js b/examples/adder.js index fbc47c3..f1b4511 100644 --- a/examples/adder.js +++ b/examples/adder.js @@ -34,12 +34,16 @@ function add(options) { function circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] }) + console.log('circuit.name: ' + circuit.name) + Object.assign(circuit, { set_value: function(variable, value) { diff --git a/examples/amplify-two-states.js b/examples/amplify-two-states.js index af6c95d..343503b 100644 --- a/examples/amplify-two-states.js +++ b/examples/amplify-two-states.js @@ -24,7 +24,9 @@ circuit(`amplify-two-states-two-times`, 5) function circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/amplify-wave.js b/examples/amplify-wave.js index 63ae952..3d72b22 100644 --- a/examples/amplify-wave.js +++ b/examples/amplify-wave.js @@ -17,7 +17,9 @@ logger.log('wave: ' + JSON.stringify(wave, null, 2)) function circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/amplify.js b/examples/amplify.js index d0bd3e6..53aea17 100644 --- a/examples/amplify.js +++ b/examples/amplify.js @@ -22,7 +22,9 @@ function amplify(value) { function circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/bell-phase.js b/examples/bell-phase.js index 7f39e2d..352cc6d 100644 --- a/examples/bell-phase.js +++ b/examples/bell-phase.js @@ -38,7 +38,9 @@ circuit('bell-phase', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/bell-state.js b/examples/bell-state.js index 39c38ff..4243caa 100644 --- a/examples/bell-state.js +++ b/examples/bell-state.js @@ -14,7 +14,9 @@ circuit('bell-opposite', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/bell-tricks.js b/examples/bell-tricks.js index aacb1c5..bcfb0a6 100644 --- a/examples/bell-tricks.js +++ b/examples/bell-tricks.js @@ -51,7 +51,9 @@ circuit('bell-phase', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/entanglement.js b/examples/entanglement.js index c147f6d..75a609c 100644 --- a/examples/entanglement.js +++ b/examples/entanglement.js @@ -12,7 +12,9 @@ circuit('entangle', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/frequency-approximate.js b/examples/frequency-approximate.js index 1b3f39c..c5d3705 100644 --- a/examples/frequency-approximate.js +++ b/examples/frequency-approximate.js @@ -42,7 +42,9 @@ function output(period, size) { function Circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/frequency.js b/examples/frequency.js index 4ff6aaa..0b202ad 100644 --- a/examples/frequency.js +++ b/examples/frequency.js @@ -36,7 +36,9 @@ function output(period, size) { function Circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/gates.js b/examples/gates.js index 1e38aa0..9b17027 100644 --- a/examples/gates.js +++ b/examples/gates.js @@ -7,7 +7,9 @@ circuit('circuit', 1).library(function(gates) { function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/ghz-state.js b/examples/ghz-state.js index 2f159da..9f05f2f 100644 --- a/examples/ghz-state.js +++ b/examples/ghz-state.js @@ -9,7 +9,9 @@ circuit('ghz', 3) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/interference.js b/examples/interference.js index ec3e2fb..357e137 100644 --- a/examples/interference.js +++ b/examples/interference.js @@ -6,7 +6,9 @@ circuit('interference', 4) function circuit(name, size, options) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/not-conditionally-toffoli-constructed.js b/examples/not-conditionally-toffoli-constructed.js index 1340031..cb392af 100644 --- a/examples/not-conditionally-toffoli-constructed.js +++ b/examples/not-conditionally-toffoli-constructed.js @@ -15,7 +15,9 @@ circuit('ccx-constructed-toffoli', 3) function circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/not-conditionally-with-one-control.js b/examples/not-conditionally-with-one-control.js index 9014d46..e2ce7cc 100644 --- a/examples/not-conditionally-with-one-control.js +++ b/examples/not-conditionally-with-one-control.js @@ -18,7 +18,9 @@ circuit('x x cx', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/not-conditionally-with-two-controls.js b/examples/not-conditionally-with-two-controls.js index af997c2..271d160 100644 --- a/examples/not-conditionally-with-two-controls.js +++ b/examples/not-conditionally-with-two-controls.js @@ -14,7 +14,9 @@ circuit('ccx true', 3) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/not.js b/examples/not.js index 163d907..2894452 100644 --- a/examples/not.js +++ b/examples/not.js @@ -11,7 +11,9 @@ circuit('setting the last bit (0) changes the leftmost bit below', 10) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/options-circuit.js b/examples/options-circuit.js index 8ae3271..bae5c46 100644 --- a/examples/options-circuit.js +++ b/examples/options-circuit.js @@ -5,37 +5,51 @@ const logger = require('../src/logger')() let circuit = require('../src/circuit.js') -circuit('circuit gates added with controls before targets', 3, { +circuit({ + name: 'circuit gates added with controls before targets', + size: 3, + logger: logger, order: ['controls', 'targets'], - logger: logger }).run() -circuit('circuit gates added with targets before controls (default)', 3, { +circuit({ + name: 'circuit gates added with targets before controls (default)', + size: 3, + logger: logger, order: ['targets', 'controls'], - logger: logger }).run() -circuit('circuit states with big endian state vector bits - lowest bit on left side', 3, { +circuit({ + name: 'circuit states with big endian state vector bits - lowest bit on left side', + size: 3, + logger: logger, endian: 'big', - logger: logger }).run() -circuit('circuit states with little endian state vector bits - lowest bit on rights side (default)', 3, { +circuit({ + name: 'circuit states with little endian state vector bits - lowest bit on rights side (default)', + size: 3, + logger: logger, endian: 'little', - logger: logger }).run() -circuit('circuit with custom state vector bit characters - "0" and "1"', 3, { +circuit({ + name: 'circuit with custom state vector bit characters - "0" and "1"', + size: 3, + logger: logger, bit_characters: ['0', '1'], - logger: logger }).run() -circuit('circuit with custom state vector bit characters - "x" and " "', 3, { +circuit({ + name: 'circuit with custom state vector bit characters - "x" and " "', + size: 3, + logger: logger, bit_characters: ['x', ' '], - logger: logger }).run() -circuit('circuit with custom simulator backend', 3, { +circuit({ + name: 'circuit with custom simulator backend', + size: 3, + logger: logger, engine: 'optimized', - logger: logger }).run() diff --git a/examples/options-dense.js b/examples/options-dense.js index 093a9ea..a18cde6 100644 --- a/examples/options-dense.js +++ b/examples/options-dense.js @@ -9,7 +9,9 @@ circuit('display non-zero state outcomes only', 3) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/options-trace-changed.js b/examples/options-trace-changed.js index e7b493e..69429d1 100644 --- a/examples/options-trace-changed.js +++ b/examples/options-trace-changed.js @@ -18,7 +18,9 @@ circuit('trace off entirely', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/options-trace.js b/examples/options-trace.js index 7e489df..c1f7301 100644 --- a/examples/options-trace.js +++ b/examples/options-trace.js @@ -15,7 +15,9 @@ circuit('apply pauli-x gate to each qubit without tracing - display result at en function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-reverse.js b/examples/phase-reverse.js index 1ad1a8c..019aac7 100644 --- a/examples/phase-reverse.js +++ b/examples/phase-reverse.js @@ -32,7 +32,9 @@ circuit('change the phase using an s-gate and then reverse using 2 t-dagger gate function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-rotation.js b/examples/phase-rotation.js index 44e4932..860643c 100644 --- a/examples/phase-rotation.js +++ b/examples/phase-rotation.js @@ -18,7 +18,9 @@ Circuit('phase-rotation-with-four-qubits-in-superposition', 4) function Circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-rz.js b/examples/phase-rz.js index 4d6c70a..66a1329 100644 --- a/examples/phase-rz.js +++ b/examples/phase-rz.js @@ -15,7 +15,9 @@ circuit('phase-rz', 1) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-s.js b/examples/phase-s.js index 8e65986..6861758 100644 --- a/examples/phase-s.js +++ b/examples/phase-s.js @@ -11,7 +11,9 @@ circuit('phase-s', 1) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-spread-rz.js b/examples/phase-spread-rz.js index befb1b3..d8dc57f 100644 --- a/examples/phase-spread-rz.js +++ b/examples/phase-spread-rz.js @@ -18,7 +18,9 @@ Circuit('spread a phase rotation of pi / 8 over five qubits', 5) function Circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-spread-s.js b/examples/phase-spread-s.js index 59b1b6b..85d5fdc 100644 --- a/examples/phase-spread-s.js +++ b/examples/phase-spread-s.js @@ -17,7 +17,9 @@ Circuit('spread a phase rotation of an s-gate over three qubits', 3) function Circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-spread-t.js b/examples/phase-spread-t.js index fec00be..9519ea4 100644 --- a/examples/phase-spread-t.js +++ b/examples/phase-spread-t.js @@ -18,7 +18,9 @@ Circuit('spread a phase rotation of a t-gate over four qubits', 4) function Circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-spread-z.js b/examples/phase-spread-z.js index 638d314..e2a59c3 100644 --- a/examples/phase-spread-z.js +++ b/examples/phase-spread-z.js @@ -18,7 +18,9 @@ Circuit('spread a phase rotation of a z-gate over two qubits', 2) function Circuit(name, size) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-t.js b/examples/phase-t.js index f9fb05f..e95e42d 100644 --- a/examples/phase-t.js +++ b/examples/phase-t.js @@ -16,6 +16,8 @@ circuit('phase-t', 1) function circuit(name, size) { return require('../src/circuit.js')(name, size, { + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase-z.js b/examples/phase-z.js index e79250b..f28751e 100644 --- a/examples/phase-z.js +++ b/examples/phase-z.js @@ -8,7 +8,9 @@ circuit('phase-z', 1) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/phase.js b/examples/phase.js index 917c47e..84dc3cd 100644 --- a/examples/phase.js +++ b/examples/phase.js @@ -15,7 +15,9 @@ circuit('phase', 1) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/quantum-fourier-transform.js b/examples/quantum-fourier-transform.js index aa03f21..fb6ac05 100644 --- a/examples/quantum-fourier-transform.js +++ b/examples/quantum-fourier-transform.js @@ -45,7 +45,9 @@ function output(period, size) { function Circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/root-of-not.js b/examples/root-of-not.js index 1a1c14b..e1efe56 100644 --- a/examples/root-of-not.js +++ b/examples/root-of-not.js @@ -21,7 +21,9 @@ circuit('x', 2) function circuit(name, size, options) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/superdense.js b/examples/superdense.js index 8497715..d52756a 100644 --- a/examples/superdense.js +++ b/examples/superdense.js @@ -27,6 +27,8 @@ function encode(value) { function Circuit(name, size, options) { let circuit = require('../src/circuit.js')(name, size, { + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/superposition.js b/examples/superposition.js index 21065f8..839e802 100644 --- a/examples/superposition.js +++ b/examples/superposition.js @@ -16,7 +16,9 @@ circuit('superposition-of-unit', 4) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/swap-conditionally.js b/examples/swap-conditionally.js index 7f786b4..0c5a162 100644 --- a/examples/swap-conditionally.js +++ b/examples/swap-conditionally.js @@ -14,7 +14,9 @@ circuit('cswap-after', 3) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/swap.js b/examples/swap.js index 3e79b8c..365a0c0 100644 --- a/examples/swap.js +++ b/examples/swap.js @@ -12,7 +12,9 @@ circuit('swap-after', 2) function circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/teleportation.js b/examples/teleportation.js index d830d3c..fe40880 100644 --- a/examples/teleportation.js +++ b/examples/teleportation.js @@ -23,7 +23,9 @@ function teleport(options) { function circuit(name, size, options) { - let circuit = require('../src/circuit.js')(name, size, { + let circuit = require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/unit-all.js b/examples/unit-all.js index 9097103..80fce84 100644 --- a/examples/unit-all.js +++ b/examples/unit-all.js @@ -18,7 +18,9 @@ Circuit('unit-placing-every-qubit-into-superposition-c', 3) function Circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/examples/unit-partial.js b/examples/unit-partial.js index 01391c2..8badfb5 100644 --- a/examples/unit-partial.js +++ b/examples/unit-partial.js @@ -15,7 +15,9 @@ circuit.run() function Circuit(name, size) { - return require('../src/circuit.js')(name, size, { + return require('../src/circuit.js')({ + name: name, + size: size, logger: logger, engine: 'optimized', order: ['targets', 'controls'] diff --git a/scratch.txt b/scratch.txt index 0e578b3..271a4c6 100644 --- a/scratch.txt +++ b/scratch.txt @@ -215,4 +215,8 @@ circuit - with simple two qubit circuit - illustate how probablity and phase are caluclated - illustate how magnitude must always add up to 1 -- illustate how probability must always add up to 100% \ No newline at end of file +- illustate how probability must always add up to 100% + +- for these examples, consider highjacking console.log instead of using logger.log + +- pass every option to circuit class using oln \ No newline at end of file diff --git a/src/circuit.js b/src/circuit.js index def54f9..db29f29 100644 --- a/src/circuit.js +++ b/src/circuit.js @@ -8,14 +8,11 @@ const circuits = {} class Circuit { - constructor(name, size, options) { + constructor(options) { - this.type = 'optimized' - this.name = name - this.size = size - this.options = options || {} - this.logger = this.options.logger - this.circuit = new (require('./derived/quantastica/circuit'))(size, options, this.logger) + Object.assign(this, options) + this.options = {} + this.circuit = new (require('./derived/quantastica/circuit'))(this.size, this.options, this.logger) this.chain = new chain(this) this.listen() } @@ -109,10 +106,10 @@ class Circuit { } } -module.exports = function(name, size, options) { +module.exports = function(options) { - if (size !== undefined) { - circuits[name] = new Circuit(name, size, options) + if (options.size !== undefined) { + circuits[options.name] = new Circuit(options) } - return circuits[name] + return circuits[options.name] }