prog += CNOT(3,0) # number=26 prog += H(0) # number=17 prog += CNOT(2,0) # number=21 prog += X(1) # number=23 prog += CNOT(2,0) # number=22 # circuit end return prog def summrise_results(bitstrings) -> dict: d = {} for l in bitstrings: if d.get(l) is None: d[l] = 1 else: d[l] = d[l] + 1 return d if __name__ == '__main__': prog = make_circuit() qvm = get_qc('4q-qvm') results = qvm.run_and_measure(prog,1024) bitstrings = np.vstack([results[i] for i in qvm.qubits()]).T bitstrings = [''.join(map(str, l)) for l in bitstrings] writefile = open("../data/startPyquil2313.csv","w") print(summrise_results(bitstrings),file=writefile) writefile.close()
prog += H(2) # number=19 prog += H(3) # number=20 prog += X(1) # number=22 prog += Y(1) # number=32 prog += X(1) # number=23 # circuit end return prog def summrise_results(bitstrings) -> dict: d = {} for l in bitstrings: if d.get(l) is None: d[l] = 1 else: d[l] = d[l] + 1 return d if __name__ == '__main__': prog = make_circuit() qvm = get_qc('5q-qvm') results = qvm.run_and_measure(prog,1024) bitstrings = np.vstack([results[i] for i in qvm.qubits()]).T bitstrings = [''.join(map(str, l)) for l in bitstrings] writefile = open("../data/startPyquil1286.csv","w") print(summrise_results(bitstrings),file=writefile) writefile.close()
prog += Y(1) # number=2 prog += CNOT(0, 1) # number=4 prog += Y(1) # number=3 # circuit end return prog def summrise_results(bitstrings) -> dict: d = {} for l in bitstrings: if d.get(l) is None: d[l] = 1 else: d[l] = d[l] + 1 return d if __name__ == '__main__': prog = make_circuit() qvm = get_qc('1q-qvm') results = qvm.run_and_measure(prog, 1024) bitstrings = np.vstack([results[i] for i in qvm.qubits()]).T bitstrings = [''.join(map(str, l)) for l in bitstrings] writefile = open("../data/startPyquil152.csv", "w") print(summrise_results(bitstrings), file=writefile) writefile.close()
]) # Define ansatz n_qubits, depth = 3, 3 from pyquil.gates import RY, CNOT def ansatz(params): p = Program() for i in range(depth): p += CNOT(2, 0) for j in range(n_qubits): p += Program(RY(params[j], j)) return p # Minimize and get approximate of the lowest eigenvalue from grove.pyvqe.vqe import VQE qc = get_qc('9q-qvm') vqe = VQE(minimizer=minimize, minimizer_kwargs={ 'method': 'nelder-mead', 'options': { 'xatol': 1.0e-2 } }) np.random.seed(999) initial_params = np.random.uniform(0.0, 2 * np.pi, size=n_qubits) result = vqe.vqe_run(ansatz, H, initial_params, samples=None, qc=qc) print(result)
def __init__( self, device, *, shots=1000, wires=None, active_reset=True, load_qc=True, readout_error=None, symmetrize_readout="exhaustive", calibrate_readout="plus-eig", **kwargs, ): pl_version = pkg_resources.get_distribution("pennylane").version if version.parse(pl_version) >= version.parse("0.14.0.dev"): raise ValueError( "Using the QPU via PennyLane-Forest is being deprecated \ with PennyLane version 0.14.0 and higher.") if readout_error is not None and load_qc: raise ValueError("Readout error cannot be set on the physical QPU") self.readout_error = readout_error self._eigs = {} self._compiled_program = None """Union[None, pyquil.ExecutableDesignator]: the latest compiled program. If parametric compilation is turned on, this will be a parametric program.""" if kwargs.get("parametric_compilation", False): # Raise a warning if parametric compilation was explicitly turned on by the user # about turning the operator estimation off # TODO: Remove the warning and toggling once a migration to the new operator estimation # API has been executed. This new API provides compatibility between parametric # compilation and operator estimation. warnings.warn( "Parametric compilation is currently not supported with operator" "estimation. Operator estimation is being turned off.") self.parametric_compilation = kwargs.get("parametric_compilation", True) if self.parametric_compilation: self._compiled_program_dict = {} """dict[int, pyquil.ExecutableDesignator]: stores circuit hashes associated with the corresponding compiled programs.""" self._parameter_map = {} """dict[str, float]: stores the string of symbolic parameters associated with their numeric values. This map will be used to bind parameters in a parametric program using PyQuil.""" self._parameter_reference_map = {} """dict[str, pyquil.quilatom.MemoryReference]: stores the string of symbolic parameters associated with their PyQuil memory references.""" timeout = kwargs.pop("timeout", None) if shots <= 0: raise ValueError("Number of shots must be a positive integer.") self.connection = super()._get_connection(**kwargs) if load_qc: self.qc = get_qc(device, as_qvm=False, connection=self.connection) if timeout is not None: self.qc.compiler.quilc_client.timeout = timeout else: self.qc = get_qc(device, as_qvm=True, connection=self.connection) if timeout is not None: self.qc.compiler.client.timeout = timeout self.num_wires = len(self.qc.qubits()) if wires is None: # infer the number of modes from the device specs # and use consecutive integer wire labels wires = range(self.num_wires) if isinstance(wires, int): raise ValueError( "Device has a fixed number of {} qubits. The wires argument can only be used " "to specify an iterable of wire labels.".format( self.num_wires)) if self.num_wires != len(wires): raise ValueError("Device has a fixed number of {} qubits and " "cannot be created with {} wires.".format( self.num_wires, len(wires))) super(QVMDevice, self).__init__(wires, shots, **kwargs) self.active_reset = active_reset self.symmetrize_readout = symmetrize_readout self.calibrate_readout = calibrate_readout self.wiring = {i: q for i, q in enumerate(self.qc.qubits())}
def __init__(self, device_name: str): # not calling super().__init__() on purpose self.device = pq.get_qc(device_name, as_qvm=False)
def __init__(self, device_name: str): self.device = pq.get_qc(device_name, as_qvm=True, noisy="noisy" in device_name)
Created on Wed May 29 18:09:04 2019 @author: bram """ import numpy as np from scipy.optimize import minimize from pyquil import Program, get_qc #============================================================================== # Variational-Quantum-Eigensolver #============================================================================== # Create connection with QVM qc = get_qc('2q-qvm') # Define matrix from pyquil.paulis import sZ H = sZ(0) # Define ansatz from pyquil.gates import RY def ansatz(params): return Program(RY(params[0], 0)) from grove.pyvqe.vqe import VQE vqe = VQE(minimizer=minimize, minimizer_kwargs={'method': 'nelder-mead', 'options':{'initial_simplex': np.array([[0.0],[0.05]]), 'xatol': 1.0e-2}})