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 test_no_truncate(self): """Test truncation with noise model option""" circuit = self.create_circuit_for_truncate() qasm_sim = Aer.get_backend('qasm_simulator') backend_options = self.BACKEND_OPTS.copy() backend_options["truncate_verbose"] = True backend_options['optimize_ideal_threshold'] = 1 backend_options['optimize_noise_threshold'] = 1 result = execute(circuit, qasm_sim, noise_model=basic_device_noise_model(self.device_properties()), shots=100, coupling_map=[[1, 0], [1, 2], [1, 3], [2, 0], [2, 1], [2, 3], [3, 0], [3, 1], [3, 2]], # 4-qubit device backend_options=backend_options).result() self.assertFalse('truncate_verbose' in result.to_dict()['results'][0]['metadata'], msg="truncate_verbose must work.")
def test_truncate_disable(self): """Test explicitly disabling truncation with noise model option""" circuit = self.create_circuit_for_truncate() qasm_sim = Aer.get_backend('qasm_simulator') backend_options = self.BACKEND_OPTS.copy() backend_options["truncate_verbose"] = True backend_options["truncate_enable"] = False backend_options['optimize_ideal_threshold'] = 1 backend_options['optimize_noise_threshold'] = 1 result = execute(circuit, qasm_sim, noise_model=basic_device_noise_model(self.device_properties()), shots=100, coupling_map=[[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 0]], # 10-qubit device backend_options=backend_options).result() self.assertFalse('truncate_qubits' in result.to_dict()['results'][0]['metadata'], msg="truncate_qubits must not work.")
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
""" To test your passes you can use the fake backend classes. Your solutions will be tested against Yorktown, Ourense and Melbourne, as well as some internal backends. """ backend = FakeMelbourne() properties = backend.properties() coupling_map = backend.configuration().coupling_map """ You must submit a pass manager which uses at least one pass you have written. Examples of creating more complex pass managers can be seen in qiskit.transpiler.preset_passmanagers""" pass_manager = PassManager() pass_manager.append(TrivialLayout(coupling_map)) pass_manager.append(MyBasicAnalysisPass()) pass_manager.append(MyBasicTransformationPass(properties)) """ This allows us to simulate the noise a real device has, so that you don't have to wait for jobs to complete on the actual backends.""" noise_model = basic_device_noise_model(properties) simulator = Aer.get_backend('qasm_simulator') """ This is the circuit we are going to look at""" qc = QuantumCircuit(2, 2) qc.h(1) qc.measure(0, 0) circuits = [qc] result_normal = execute(circuits, simulator, coupling_map=coupling_map).result().get_counts() # NB we include the noise model in the second run result_noisy = execute(circuits, simulator, noise_model=noise_model, coupling_map=coupling_map).result().get_counts()
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