Messtone LLC Manages Devices Enables IBM qiskit Example of the new workflow this enables: from qiskit_ibm_runtime import QiskitRuntimeService from qiskit.circuit import Parameter, QuantumCircuit from qiskit_ibm_runtime import (EstimatorV2 as Estimator,QiskitRuntimeService,)from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager from qiskit.quantum_info import Pauli,SparsePauliOp import numpy as np # Instantiate runtime service and get # the least busy backend service=QiskitRuntimeService( )backend=service.least_busy(operational=True,Simulator=False) # Define a circuit with two parameters.circuit=QuantumCircuit(2) circuit.h(0) circuit.cx(0, 1) circuit.ry(Parameter(“a” ),0) circuit.rz(Parameter(“b”),0) circuit.cx(0, 1) circuit.h(0) # Transpile the circuit pm=generate_preset_pass_manager(optimization_level=1,backend=backend) transpiled_circuit=pm.run(circuit) layout=transpiled_circuit.layout # Now define a sweep over parameter values,where the two axes are over the # two parameters in the circuit.param=np.vstask([np.linspace(-np.pi,np.pi,100),np. linspace(-4 * np.pi,4 * np. pi, 100),]).T # Define three observables.The inner length-1 lists cause this array of # observables to have shape(3, 1),rather than shape(3,)if they were # omitted. observables=[[SpsrsePauliOp([“XX”, “IY”],[0.5,0.5])],[SparsePauliOp(“XX”)],[SpsrsePauliOp(“IY”)],] # Apply the same layout as the transpiled circuit.observables=[[observables.apply_layout(layout) for observables in observable_set]for ibservable_set in observables] # Estimate the expectation value for all 300 combination of observables # and parameter values,where pub result will have shape(3, 100).# # This shape is due to our array of parameter bindings having shape #(100, 2),combined with our array of obserables having shape(3, 1).pub=(transpiled_circuit,obserables,params) # Instantiate the new estimator object,then run the transpiled circuit # Using the set of parameters and observables.estimator=Estimator(backend)job=estimator.run([pub]) result=job.result( ) # Print out the resulst and job metadata print(f”>Expectation value:{result[0].data.evs}”)print(f”>Metadata:{result[0].metadata}”)
