F1 = 3 - (np.sin(2 * a_beta)**2 * np.sin(2 * a_gamma)**2 - 0.5 * np.sin( 4 * a_beta) * np.sin(4 * a_gamma)) * (1 + np.cos(4 * a_gamma)**2) result = np.where(F1 == np.amax(F1)) a = list(zip(result[0], result[1]))[0] gamma = a[0] * step_size beta = a[1] * step_size prog = make_circuit(4) sample_shot = 3962 writefile = open("../data/startQiskit_QC263.csv", "w") # prog.draw('mpl', filename=(kernel + '.png')) IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q') provider.backends() backend = provider.get_backend("ibmq_5_yorktown") circuit1 = transpile(prog, FakeYorktown()) circuit1.measure_all() prog = circuit1 info = execute(prog, backend=backend, shots=sample_shot).result().get_counts() print(info, file=writefile) print("results end", file=writefile) print(circuit1.depth(), file=writefile) print(circuit1, file=writefile) writefile.close()
# -*- coding: utf-8 -*- """ Created Nov 2020 @author: hassi """ from qiskit import QuantumCircuit, execute from qiskit import IBMQ from qiskit.tools.monitor import job_monitor from IPython.core.display import display print("Getting provider...") if not IBMQ.active_account(): IBMQ.load_account() provider = IBMQ.get_provider() print("Ch 4: Quantum coin toss on IBM Q backend") print("----------------------------------------") qc = QuantumCircuit(2, 2) qc.h(0) qc.cx(0, 1) qc.measure([0, 1], [0, 1]) display(qc.draw('mpl')) from qiskit.providers.ibmq import least_busy backend = least_busy( provider.backends(n_qubits=5, operational=True, simulator=False))
# In[10]: result = execute(circuit, backend = simulator).result() # In[11]: plot_histogram(result.get_counts(circuit)) # In[12]: provider = IBMQ.get_provider('ibm-q') # In[14]: qcomp = provider.get_backend('ibmq_16_melbourne') # In[15]: job = execute(circuit, backend = qcomp) # In[ ]:
from qiskit import IBMQ, Aer from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister import matplotlib.pyplot as plt import os from rwutil import * OUTPUT = "output" IBMQ.load_account() Prov = IBMQ.get_provider(group='open') BACKENDS = { 'qasm_simulator': (Aer.get_backend('qasm_simulator'), True), 'ibmq_qasm_simulator': (Prov.get_backend('ibmq_qasm_simulator'), False), 'ibmq_london': (Prov.get_backend('ibmq_qasm_simulator'), False), 'ibmq_vigo': (Prov.get_backend('ibmq_qasm_simulator'), False) } SHOTS = 1000 T = [*range(0, 5)] def shift_gate(): q = QuantumRegister(3) circuit = QuantumCircuit(q, name='shift') circuit.ccx(0, 1, 2) circuit.cx(0, 1) circuit.x(0) circuit.x(1) circuit.ccx(0, 1, 2)
# uncompute for i in range(self.n - 1, 1, -1): self.circ.ccx(self.ctrl[i], self.anc[i - 2], self.anc[i - 1]) self.circ.ccx(self.ctrl[0], self.ctrl[1], self.anc[0]) def calc_theta(self, p1, p0): return 2 * np.arctan(np.sqrt((p1) / (p0))) #if __name__=='__main__': from jupyterthemes import jtplot jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False) from qiskit.tools.jupyter import * from qiskit import IBMQ IBMQ.load_account() # provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main') provider = IBMQ.get_provider(hub='ibm-q-oxford', group='on-boarding', project='on-boarding-proj') from qiskit import BasicAer backend = BasicAer.get_backend('unitary_simulator') n = 3 parents = np.random.rand(n * 2) child = np.random.rand(2**(n + 1)) b = byskit(provider, backend, n, parents, child)
def _initialize_backend(self, backend="ibmq_qasm_simulator"): #self.backend = IBMQ.get_backend(backend) #TO-DO once IBMQ.get_provider() actually works use that self.backend = IBMQ.get_provider().get_backend(backend)
# **1.3. Experimento:** Cuando un qubit esta inicializado en $|0>\rangle$ el resultado de la medición debe ser, en teoria, siempre $|0>\rangle$(con probabilidad del 100%). 1000 shots en computador cuantico real # In[14]: from qiskit import IBMQ IBMQ.load_account() # In[17]: #Ejecución en un computador cuantico real proveedor = IBMQ.get_provider('ibm-q') comp_cuantico = proveedor.get_backend('ibmq_burlington') ejecucion = execute(circuito_12, backend=comp_cuantico,shots=1000) from qiskit.tools.monitor import job_monitor job_monitor(ejecucion) resultado = ejecucion.result() conteos = resultado.get_counts() print(conteos) # In[20]:
if not backend: backend = Aer.get_backend('qasm_simulator') elif type(backend) == str: if 'state' in backend: backend = Aer.get_backend('statevector_simulator') state_vector = execute(circuit, backend).result().get_statevector() return state_vector else: try: from warnings import filterwarnings filterwarnings("ignore") IBMQ.load_account() provider = IBMQ.get_provider("ibm-q") backend = provider.get_backend(backend) except Exception as e: print(f'Error: could not get IBMQ provider, {e}') assert None if display_job_status: print(f'running on: {backend.name()}') if measure: circuit.measure(range(len(circuit.clbits)), range(len(circuit.clbits))) if draw: print(circuit.draw()) circuit.data = [e for e in circuit.data if type(e[0]) != Barrier]
import numpy as np from qiskit import IBMQ from qiskit import pulse # This is where we access all of our Pulse features! from qiskit.pulse import Play from qiskit.pulse import pulse_lib # This Pulse module helps us build sampled pulses for common pulse shapes from qiskit import assemble from qiskit.tools.monitor import job_monitor """ Программа для сбора данных с квантовго компьютера IBM Armonk """ IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main') backend = provider.get_backend('ibmq_armonk') backend_config = backend.configuration() assert backend_config.open_pulse, "Backend doesn't support Pulse" dt = backend_config.dt print(f"Sampling time: {dt * 1e9} ns") backend_defaults = backend.defaults() qubit = 0 # достаем из текстового файла частоту кубита и амплитуду pi импулса with open("qubit_params.txt", "r") as f: rough_qubit_frequency, pi_amp = list(map(lambda x: float(x.strip()), f.readlines())) us = 1.0e-6 # Microseconds scale_factor = 1e-14
from functions import QuantumNeuralNetwork, EffectiveDimension from qiskit.aqua import QuantumInstance from qiskit import IBMQ, Aer from qiskit.circuit.library import ZFeatureMap, RealAmplitudes from qiskit.providers.aer.noise.noise_model import NoiseModel import numpy as np TOKEN = 'insert token here' IBMQ.save_account(TOKEN, overwrite=True) provider = IBMQ.load_account() provider = IBMQ.get_provider(hub='ibm-q-internal', group='deployed', project='default') backend_name = 'ibmq_montreal' backend_ibmq = provider.get_backend(backend_name) properties = backend_ibmq.properties() coupling_map = backend_ibmq.configuration().coupling_map noise_model = NoiseModel.from_backend(properties) layout = [1, 2, 3, 5, 8, 11, 14, 13, 12, 10] qi_ibmq_noise_model = QuantumInstance(backend=Aer.get_backend('qasm_simulator'), noise_model=noise_model, optimization_level=0, shots=8000, seed_transpiler=2, initial_layout=layout) qi = qi_ibmq_noise_model compile_config = {'initial_layout': layout, 'seed_transpiler': 2, 'optimization_level': 3 } n = [1000, 2000, 8000, 10000, 40000, 60000, 100000, 150000, 200000, 500000, 1000000, 10000000, 10000000000, 10000000000000] qubits = 10 fm = ZFeatureMap(qubits, reps=1) varform = RealAmplitudes(qubits, reps=9, entanglement='full') qnet = QuantumNeuralNetwork(fm, varform) ed = EffectiveDimension(qnet, 100, 100)