def calculation(): setup_logging() qobj, theta = create_experiment_qobj( factory=circuit, other_arguments={'use_barriers': use_barriers}, weights=[] if instead_general_weights_use_hadamard else [1 / np.sqrt(2), 1 / np.sqrt(2)], theta_start=0.0, theta_end=2 * np.pi, theta_step=0.1, pm=pass_manager, device=qasm_simulator(), qobj_id=id, use_dask=True) # Experiment ex = experiment(id, backend(), qobj=qobj) ex.parameters['backend'] = backend().name() ex.parameters['use_barriers'] = use_barriers ex.parameters['circuit_factory'] = circuit.__name__ ex.parameters[ 'use_generic_weights_circuit'] = not instead_general_weights_use_hadamard # Simulation if no_noise: noise_model = None device_properties = None # type: Optional[BackendProperties] gate_times = [] else: device_properties = backend().properties( ) # type: Optional[BackendProperties] gate_times = get_gate_times(backend()) noise_model = basic_device_noise_model( device_properties, gate_times=gate_times, temperature=0) # type: Optional[NoiseModel] sim = simulation(id, qasm_simulator(), qobj=qobj, noise_model=noise_model) sim.set_theta(theta) sim.parameters['backend'] = backend().name() sim.parameters['use_barriers'] = use_barriers sim.parameters['circuit_factory'] = circuit.__name__ sim.parameters[ 'use_generic_weights_circuit'] = not instead_general_weights_use_hadamard if noise_model is not None: sim.parameters['device_properties'] = device_properties.to_dict(), if noise_model is not None: sim.parameters['gate_times'] = gate_times LOG.info("Done with %s.", id) return ex, sim
def calculation(): setup_logging() pass_manager = create_direction_only_pass_manager(backend()) qobj, theta = create_experiment_qobj( factory=lib.create_swap_test_circuit, other_arguments={ 'use_barriers': True, 'readout_swap': readout_swap }, weights=[1 / np.sqrt(2), 1 / np.sqrt(2)], theta_start=0.0, theta_end=2 * np.pi, theta_step=0.1, pm=pass_manager, device=qasm_simulator(), qobj_id=id, use_dask=True) # Simulation if no_noise: noise_model = None device_properties = None # type: Optional[BackendProperties] gate_times = [] else: device_properties = backend().properties( ) # type: Optional[BackendProperties] gate_times = get_gate_times(backend()) noise_model = basic_device_noise_model( device_properties, gate_times=gate_times, temperature=0) # type: Optional[NoiseModel] sim = simulation(id, qasm_simulator(), qobj=qobj, noise_model=noise_model) sim.set_theta(theta) sim.parameters['backend'] = backend().name() sim.parameters['use_barriers'] = use_barriers sim.parameters[ 'use_generic_weights_circuit'] = not instead_general_weights_use_hadamard sim.parameters['circuit_factory'] = circuit.__name__ if noise_model is not None: sim.parameters['device_properties'] = device_properties.to_dict(), if noise_model is not None: sim.parameters['gate_times'] = gate_times return sim
def calculation(): setup_logging() # Try to use a noise model if we possible if copies == 1: device_properties = ibmqx4().properties() gate_times = get_gate_times(ibmqx4()) elif copies <= 5: device_properties = ibmq_16_melbourne().properties() gate_times = get_gate_times(ibmq_16_melbourne()) else: device_properties = None gate_times = None # If we don't have device properties we can't create a noise model if device_properties is None: noise_model = None # type: Optional[NoiseModel] else: noise_model = basic_device_noise_model( device_properties, gate_times=gate_times, temperature=0) # type: Optional[NoiseModel] pass_manager = create_optimize_only_pass_manager(qasm_simulator()) qobj, theta = create_experiment_qobj( factory=lib.create_product_state_n_copies_circuit, weights=[1 / np.sqrt(2), 1 / np.sqrt(2)], theta_start=0.0, theta_end=2 * np.pi, theta_step=0.1, pm=pass_manager, device=qasm_simulator(), qobj_id=id, use_dask=True, other_arguments={'copies': copies}) sim = simulation(id, qasm_simulator(), qobj=qobj, noise_model=noise_model) sim.set_theta(theta) return sim
def calculation(): setup_logging() weights = [] if instead_general_weights_use_hadamard else [ 1 / np.sqrt(2), 1 / np.sqrt(2) ] circuit = lib.create_swap_test_circuit # type: Callable[[List[float], float, Optional[dict]], QuantumCircuit] backend = ibmqx4 # type: Callable[[], BaseBackend] if backend_enum == BackendEnum.IBMQX2: circuit = lib.create_swap_test_circuit backend = ibmqx2 elif backend_enum == BackendEnum.IBMQX4: circuit = lib.create_swap_test_circuit backend = ibmqx4 elif backend_enum == BackendEnum.IBMQ_OURENSE: circuit = lib.create_swap_test_circuit_ourense backend = ibmq_ourense elif backend_enum == BackendEnum.IBMQ_VIGO: circuit = lib.create_swap_test_circuit_ourense backend = ibmq_vigo else: raise ValueError("Given backend not supported.") pass_manager = create_direction_only_pass_manager(backend()) qobj, theta = create_experiment_qobj(factory=circuit, other_arguments={ 'use_barriers': use_barriers, 'readout_swap': readout_swap }, weights=weights, theta_start=0.0, theta_end=2 * np.pi, theta_step=0.1, pm=pass_manager, device=qasm_simulator(), qobj_id=id, use_dask=not dont_use_dask) if no_experiment: ex = None else: ex = experiment(id, backend(), qobj=qobj) ex.set_theta(theta) ex.parameters['backend'] = backend().name() ex.parameters['use_barriers'] = use_barriers ex.parameters['readout_swap'] = readout_swap ex.parameters[ 'use_generic_weights_circuit'] = not instead_general_weights_use_hadamard ex.parameters['circuit_factory'] = circuit.__name__ if no_noise: noise_model = None device_properties = None # type: Optional[BackendProperties] gate_times = [] else: device_properties = backend().properties( ) # type: Optional[BackendProperties] gate_times = get_gate_times(backend()) noise_model = basic_device_noise_model( device_properties, gate_lengths=gate_times, temperature=0) # type: Optional[NoiseModel] sim = simulation(id, qasm_simulator(), qobj=qobj, noise_model=noise_model) sim.parameters['backend'] = backend().name() sim.parameters['use_barriers'] = use_barriers sim.parameters['readout_swap'] = readout_swap sim.parameters[ 'use_generic_weights_circuit'] = not instead_general_weights_use_hadamard sim.parameters['circuit_factory'] = circuit.__name__ if noise_model is not None: sim.parameters['device_properties'] = device_properties.to_dict(), if noise_model is not None: sim.parameters['gate_times'] = gate_times sim.set_theta(theta) if no_experiment: ex = sim return ex, sim