Loading...

import js gate = pn.widgets.Select(name='Gate', options=[None] + [gate.upper() for gate in gates]).servable(target='gate-widget') arg = pn.widgets.NumberInput(name='Angle (in degrees)', disabled=True).servable(target='arg-widget') go = pn.widgets.Button(name='Apply', button_type='primary').servable(target='go-widget') info = pn.pane.Str('').servable(target='info') component = SingleQubit() @pn.depends(gate, watch=True) def select_gate(v): arg.disabled = gate.value is None or not (gate.value.lower() in arg_gates) print('gate', v) @pn.depends(go, watch=True) def apply(v): global out if go.value is True and gate.value is not None: # add_gate(qc, [], 0, gate.value.lower(), arg.value/180*pi if gate.value.lower() in arg_gates else None) component.apply_gate(gate.value.lower(), arg.value) gate.value = None arg.value = None arg.disabled = True go.value = False s = component.get_state() qc_str = circuit_to_string(component.qc) #component.get_circuit() js.draw(qc_str) out = f'Step {component.last_step()}\n-------\n\n{s}\n\n{out}' info.object = out component.reset() out = f'Initial state\n-------------\n\n{component.get_state()}' info.object = out