前提・実現したいこと
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
1from copy import deepcopy 2from functools import partial 3import numpy as np 4import matplotlib.pyplot as plt 5import multiprocessing as mp 6import pickle 7import pprint 8import scipy.optimize as opt 9 10from qiskit import pulse, transpile, assemble, schedule, IBMQ, quantum_info as qi 11from qiskit.pulse import library as pulse_lib 12from qiskit.pulse.reschedule import align_measures 13from qiskit.ignis.verification import randomized_benchmarking as rb 14 15import qiskit 16 17# utility for pulse schedule generation 18from MyPythonLibrary.cr_pulse_utils import create_cr_circuit, var_amp, var_phi 19 20# utility for quantum process tomography 21from MyPythonLibrary.qpt_utils import create_qpt_experiment, extract_choi_matrix 22 23# utility for randomized benchmarking 24from MyPythonLibrary.rb_utils import create_rb_experiment, cache_circuit 25 26# utility for analysis 27from MyPythonLibrary.analysis_utils import (cr_3rd_order_perturbation, local_fidelity_optimization, 28 optimize_circuit, expectation_val, hamiltonian_reconstruction, 29 plot_quantum_channel, ExperimentRunner) 30from google.colab import drive 31drive.mount('/content/drive') 32 33# use cache data 34use_cache = True 35 36# data data_directory 37data_dir = './data/custom_cnot_experiments' 38 39account_provider = IBMQ.load_account() 40hub = 'ibm-q' 41group = 'open' 42project = 'main' 43 44# target backend 45backend_name = 'ibmq_manila' 46 47provider = IBMQ.get_provider(group = group) 48backend = provider.get_backend(backend_name) 49 50######################## 51# # 52# Setup of experiments # 53# # 54######################## 55 56# control qubit index 57control = 1 58 59# target qubit index 60target = 0 61 62# control channel index 63u_index = 1 64 65# maximum cross resonance amplitude in this experiment 66max_cr_amplitude = 0.35 67 68# sample number restriction 69alignment = 16 70 71# initial cross resonance pulse parameters 72cr_params = {'duration': 53 * alignment, 'amp': var_amp, 'phi': var_phi, 73 'sigma': 2 * alignment, 'risefall': 4 * alignment} 74 75# backend information 76config = backend.configuration() 77defaults = backend.defaults() 78properties = backend.properties() 79 80# sorted list of qubits used in the experiments 81cr_qubits = sorted([control, target]) 82 83# quantum registers for handling abstracted schedule 84qregs = qiskit.QuantumRegister(config.n_qubits) 85 86# channels for visualization 87channels = [pulse.DriveChannel(control), pulse.DriveChannel(target), pulse.ControlChannel(u_index)] 88 89shots = 1024 90 91# create QuantumCircuit layer abstraction of CR pulse schedule. 92# this technique is useful to incorporate pulse schedule with circuit instruction to 93# program complicated calibration sequence while keeping context of operation. 94cr_cal_circ, ext_inst_map, ext_basis_gates = create_cr_circuit( 95 cross_resonance_params=cr_params, 96 control=control, 97 target=target, 98 u_index=u_index, 99 q_regs=qregs, 100 inst_map=defaults.instruction_schedule_map, 101 basis_gates=config.basis_gates, 102 use_echo=True) 103cr_amps = np.linspace(-max_cr_amplitude, max_cr_amplitude, 20) 104 105# setup CR Rabi experiment with Z measurement 106cr_rabi_circ = cr_cal_circ.copy() 107cr_rabi_circ.measure_active() 108 109cr_rabi_circs = [] 110for cind, cr_amp in enumerate(cr_amps): 111 fixed_cr_circ = cr_rabi_circ.bind_parameters({var_amp: cr_amp, var_phi: 0}) 112 fixed_cr_circ.name = 'cr_rabi_circ_%d' % cind 113 cr_rabi_circs.append(fixed_cr_circ) 114 115transpiled_circuits = transpile(cr_rabi_circs, backend, basis_gates=ext_basis_gates, optimization_level=0) 116scheds = schedule(transpiled_circuits, backend,ext_inst_map)##ここです 117 118qobj_1_1 = assemble(scheds, backend, meas_level=2, shots=shots)
試したこと
python
1 def cr_designer(*args, flip): 2 """create cr pulse schedule.""" 3 # parse parameters for qiskit expression format 4 config = {} 5 for param in __reserved: 6 if param in sched_vars: 7 # NOTE: circuit bind method stores parameters as args. 8 expression = args[list(sched_vars.keys()).index(param)] 9 else: 10 expression = sched_args[param] 11 config[param] = float(expression) 12 if param == 'duration': 13 config[param] = int(config[param]) 14 15 # cross resonance pulse 16 cr_pulse = _cr_pulse(duration=config['duration'], amp=config['amp'], 17 phi=config['phi'] + np.pi if flip else config['phi'], 18 sigma=config['sigma'], risefall=config['risefall'], 19 name='CR90%s_u_var' % ('m' if flip else 'p'))
python
1def get( 2 self, 3 instruction: Union[str, Instruction], 4 qubits: Union[int, Iterable[int]], 5 *params: Union[complex, ParameterExpression], 6 **kwparams: Union[complex, ParameterExpression], 7 ) -> Union[Schedule, ScheduleBlock]: 8 """Return the defined :py:class:`~qiskit.pulse.Schedule` or 9 :py:class:`~qiskit.pulse.ScheduleBlock` for the given instruction on the given qubits. 10 11 If all keys are not specified this method returns schedule with unbound parameters. 12 13 Args: 14 instruction: Name of the instruction or the instruction itself. 15 qubits: The qubits for the instruction. 16 *params: Command parameters for generating the output schedule. 17 **kwparams: Keyworded command parameters for generating the schedule. 18 19 Returns: 20 The Schedule defined for the input. 21 22 Raises: 23 PulseError: When invalid parameters are specified. 24 """ 25 instruction = _get_instruction_string(instruction) 26 self.assert_has(instruction, qubits) 27 generator = self._map[instruction][_to_tuple(qubits)] 28 29 _error_message = ( 30 f"*params={params}, **kwparams={kwparams} do not match with " 31 f"the schedule generator signature {generator.signature}." 32 ) 33 34 function = generator.function 35 if callable(function): 36 try: 37 # callables require full binding, but default values can exist. 38 binds = generator.signature.bind(*params, **kwparams) 39 binds.apply_defaults() 40 except TypeError as ex: 41 raise PulseError(_error_message) from ex 42 return function(**binds.arguments)
get関数の一番下のソースコードを見るとfunctionに**argを入れているが、cr_designer関数の引数は*argなので悪さが起こっているのかと思って色々試してみたが、知識不足が祟ってerrorが増えるだけだった。
あなたの回答
tips
プレビュー