Skip to content

Commit

Permalink
Fix collab install (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
amirebrahimi authored May 19, 2022
1 parent 20a7c41 commit f6abd1f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
50 changes: 25 additions & 25 deletions js/lib/quirk.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,48 @@ var quirkUrl = require('./quirk.html');
// differ from the defaults will be specified.
var QuirkModel = widgets.DOMWidgetModel.extend({
defaults: _.extend(widgets.DOMWidgetModel.prototype.defaults(), {
_model_name : 'QuirkModel',
_view_name : 'QuirkView',
_model_module : 'pyquirk',
_view_module : 'pyquirk',
_model_module_version : '0.1.6',
_view_module_version : '0.1.6',
width : 1000,
height : 450,
scale : 0.5,
_model_name: 'QuirkModel',
_view_name: 'QuirkView',
_model_module: 'pyquirk',
_view_module: 'pyquirk',
_model_module_version: '0.1.7',
_view_module_version: '0.1.7',
width: 1000,
height: 450,
scale: 0.5,
})
});

var QuirkView = widgets.DOMWidgetView.extend({

render: function() {
render: function () {

model = this.model;
width = model.get('width');
height = model.get('height');
scale = model.get('scale');

this.container = document.createElement('div')
this.container.id = "pyquirk"
this.container.style.width = `${width}px`;
this.container.style.height = `${height}px`;

this.frame = document.createElement('iframe');
this.frame.id = "iframe";
this.frame.style.transformOrigin = "0 0";
this.frame.style.transform = `scale(${scale})`;
this.frame.style.width = `${1/scale * 100}%`;
this.frame.style.height = `${1/scale * 100}%`;
this.frame.style.width = `${1 / scale * 100}%`;
this.frame.style.height = `${1 / scale * 100}%`;
this.frame.src = quirkUrl.default;
this.container.appendChild(this.frame);
this.frame.onload = function() {

this.frame.onload = function () {
console.log("IFRAME loaded: " + this.src);
this.contentWindow.onclick = function() {
this.contentWindow.onclick = function () {
qasm = this.document.getElementById('export-qasm-pre').innerText;
model.set('circuit_qasm', qasm);
model.save_changes();
};
};
};

this.el.appendChild(this.container);
Expand All @@ -73,22 +73,22 @@ var QuirkView = widgets.DOMWidgetView.extend({
this.model.on('change:scale', this.update_scale, this);
},

update_width: function(property) {
update_width: function (property) {
this.container.style.width = `${this.model.get('width')}px`;
},

update_height: function(property) {
update_height: function (property) {
this.container.style.height = `${this.model.get('height')}px`;
},

update_scale: function(property) {
update_scale: function (property) {
scale = this.model.get('scale');
this.frame.style.transform = `scale(${scale})`;
this.frame.style.width = `${1/scale * 100}%`;
this.frame.style.height = `${1/scale * 100}%`;
this.frame.style.width = `${1 / scale * 100}%`;
this.frame.style.height = `${1 / scale * 100}%`;
},
circuit_updated: function() {

circuit_updated: function () {
this.frame.src = quirkUrl.default + `#circuit={"cols":${this.model.get("value").replaceAll("'", "\"")}}`;
}
});
Expand Down
4 changes: 2 additions & 2 deletions js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pyquirk",
"version": "0.1.6",
"version": "0.1.7",
"description": "A Python widget for Quirk to use in to be used in Jupyter notebooks, JupyterLab, and the IPython kernel.",
"author": "Aditya Giridharan",
"main": "lib/index.js",
Expand Down Expand Up @@ -51,4 +51,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion pyQuirk/_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Module version
version_info = (0, 1, 6, 'beta', 0)
version_info = (0, 1, 7, 'beta', 0)

# Module version stage suffix map
_specifier_ = {'alpha': 'a', 'beta': 'b', 'candidate': 'rc', 'final': ''}
Expand Down
12 changes: 6 additions & 6 deletions pyQuirk/quirk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class Quirk(widgets.DOMWidget):
_model_module = Unicode('pyquirk').tag(sync=True)

# Version of the front-end module containing widget view
_view_module_version = Unicode('^0.1.0').tag(sync=True)
_view_module_version = Unicode('^0.1.7').tag(sync=True)

# Version of the front-end module containing widget model
_model_module_version = Unicode('^0.1.0').tag(sync=True)
_model_module_version = Unicode('^0.1.7').tag(sync=True)

# Widget specific property.
# Widget properties are defined as traitlets. Any property tagged with `sync=True`
Expand All @@ -39,7 +39,7 @@ def update_circuit(self, circuit):
qasm = circuit.qasm()
self.circuit_qasm = qasm
self.update_from_qasm(qasm)

def update_from_qasm(self, qasm):
self.value = qasm_to_quirk(qasm)

Expand Down Expand Up @@ -81,14 +81,14 @@ def qasm_to_quirk(qasm):

num_qubits = 0
num_clbits = 0

qubit_match = qubit_search.findall(qasm)
clbit_match = clbit_search.findall(qasm)
if qubit_match:
num_qubits = int(qubit_match[0])
if clbit_match:
num_clbits = int(clbit_match[0])

qreg = ""
creg = ""

Expand All @@ -107,7 +107,7 @@ def qasm_to_quirk(qasm):
continue
if 'include' in instr:
continue

if 'qreg' in instr:
qreg = instr.replace('qreg ', '').split('[')[0]
continue
Expand Down

0 comments on commit f6abd1f

Please sign in to comment.