前提・実現したいこと
PythonのQiskitで論文(https://iopscience.iop.org/article/10.1088/2058-9565/aba404/meta)の再現をしていたところ、何やら論文の関数(cr_pulse_utils.pyの中のcr_designer関数)とqiskitの方の関数(qiskit.schedule)で齟齬が起きているようです。
論文で使用されたソースコードは(https://doi.org/10.5281/zenodo.3751565)で公開されています。
Errorを解決したいです。
自分はかなりprograming初学者で、必要な情報がここに詰められているかも怪しいので、足りない情報があればリクエストお願いします泣
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-49-58d3fa8a243e> in <module>() 12 13 transpiled_circuits = transpile(cr_rabi_circs, backend, basis_gates=ext_basis_gates, optimization_level=0) ---> 14 scheds = schedule(transpiled_circuits, backend,ext_inst_map) 15 16 qobj_1_1 = assemble(scheds, backend, meas_level=2, shots=shots) 5 frames /usr/local/lib/python3.7/dist-packages/qiskit/pulse/instruction_schedule_map.py in get(self, instruction, qubits, *params, **kwparams) 197 except TypeError as ex: 198 raise PulseError(_error_message) from ex --> 199 return function(**binds.arguments) 200 201 try: TypeError: cr_designer() got an unexpected keyword argument 'args'
該当のソースコード
Python
from copy import deepcopy from functools import partial import numpy as np import matplotlib.pyplot as plt import multiprocessing as mp import pickle import pprint import scipy.optimize as opt from qiskit import pulse, transpile, assemble, schedule, IBMQ, quantum_info as qi from qiskit.pulse import library as pulse_lib from qiskit.pulse.reschedule import align_measures from qiskit.ignis.verification import randomized_benchmarking as rb import qiskit # utility for pulse schedule generation from MyPythonLibrary.cr_pulse_utils import create_cr_circuit, var_amp, var_phi # utility for quantum process tomography from MyPythonLibrary.qpt_utils import create_qpt_experiment, extract_choi_matrix # utility for randomized benchmarking from MyPythonLibrary.rb_utils import create_rb_experiment, cache_circuit # utility for analysis from MyPythonLibrary.analysis_utils import (cr_3rd_order_perturbation, local_fidelity_optimization, optimize_circuit, expectation_val, hamiltonian_reconstruction, plot_quantum_channel, ExperimentRunner) from google.colab import drive drive.mount('/content/drive') # use cache data use_cache = True # data data_directory data_dir = './data/custom_cnot_experiments' account_provider = IBMQ.load_account() hub = 'ibm-q' group = 'open' project = 'main' # target backend backend_name = 'ibmq_manila' provider = IBMQ.get_provider(group = group) backend = provider.get_backend(backend_name) ######################## # # # Setup of experiments # # # ######################## # control qubit index control = 1 # target qubit index target = 0 # control channel index u_index = 1 # maximum cross resonance amplitude in this experiment max_cr_amplitude = 0.35 # sample number restriction alignment = 16 # initial cross resonance pulse parameters cr_params = {'duration': 53 * alignment, 'amp': var_amp, 'phi': var_phi, 'sigma': 2 * alignment, 'risefall': 4 * alignment} # backend information config = backend.configuration() defaults = backend.defaults() properties = backend.properties() # sorted list of qubits used in the experiments cr_qubits = sorted([control, target]) # quantum registers for handling abstracted schedule qregs = qiskit.QuantumRegister(config.n_qubits) # channels for visualization channels = [pulse.DriveChannel(control), pulse.DriveChannel(target), pulse.ControlChannel(u_index)] shots = 1024 # create QuantumCircuit layer abstraction of CR pulse schedule. # this technique is useful to incorporate pulse schedule with circuit instruction to # program complicated calibration sequence while keeping context of operation. cr_cal_circ, ext_inst_map, ext_basis_gates = create_cr_circuit( cross_resonance_params=cr_params, control=control, target=target, u_index=u_index, q_regs=qregs, inst_map=defaults.instruction_schedule_map, basis_gates=config.basis_gates, use_echo=True) cr_amps = np.linspace(-max_cr_amplitude, max_cr_amplitude, 20) # setup CR Rabi experiment with Z measurement cr_rabi_circ = cr_cal_circ.copy() cr_rabi_circ.measure_active() cr_rabi_circs = [] for cind, cr_amp in enumerate(cr_amps): fixed_cr_circ = cr_rabi_circ.bind_parameters({var_amp: cr_amp, var_phi: 0}) fixed_cr_circ.name = 'cr_rabi_circ_%d' % cind cr_rabi_circs.append(fixed_cr_circ) transpiled_circuits = transpile(cr_rabi_circs, backend, basis_gates=ext_basis_gates, optimization_level=0) scheds = schedule(transpiled_circuits, backend,ext_inst_map)##ここです qobj_1_1 = assemble(scheds, backend, meas_level=2, shots=shots)
試したこと
python
def cr_designer(*args, flip): """create cr pulse schedule.""" # parse parameters for qiskit expression format config = {} for param in __reserved: if param in sched_vars: # NOTE: circuit bind method stores parameters as args. expression = args[list(sched_vars.keys()).index(param)] else: expression = sched_args[param] config[param] = float(expression) if param == 'duration': config[param] = int(config[param]) # cross resonance pulse cr_pulse = _cr_pulse(duration=config['duration'], amp=config['amp'], phi=config['phi'] + np.pi if flip else config['phi'], sigma=config['sigma'], risefall=config['risefall'], name='CR90%s_u_var' % ('m' if flip else 'p'))
python
def get( self, instruction: Union[str, Instruction], qubits: Union[int, Iterable[int]], *params: Union[complex, ParameterExpression], **kwparams: Union[complex, ParameterExpression], ) -> Union[Schedule, ScheduleBlock]: """Return the defined :py:class:`~qiskit.pulse.Schedule` or :py:class:`~qiskit.pulse.ScheduleBlock` for the given instruction on the given qubits. If all keys are not specified this method returns schedule with unbound parameters. Args: instruction: Name of the instruction or the instruction itself. qubits: The qubits for the instruction. *params: Command parameters for generating the output schedule. **kwparams: Keyworded command parameters for generating the schedule. Returns: The Schedule defined for the input. Raises: PulseError: When invalid parameters are specified. """ instruction = _get_instruction_string(instruction) self.assert_has(instruction, qubits) generator = self._map[instruction][_to_tuple(qubits)] _error_message = ( f"*params={params}, **kwparams={kwparams} do not match with " f"the schedule generator signature {generator.signature}." ) function = generator.function if callable(function): try: # callables require full binding, but default values can exist. binds = generator.signature.bind(*params, **kwparams) binds.apply_defaults() except TypeError as ex: raise PulseError(_error_message) from ex return function(**binds.arguments)
get関数の一番下のソースコードを見るとfunctionに**argを入れているが、cr_designer関数の引数は*argなので悪さが起こっているのかと思って色々試してみたが、知識不足が祟ってerrorが増えるだけだった。
まだ回答がついていません
会員登録して回答してみよう