oqc-community / qat

QAT is a quantum compiler and runtime focused on low-level, just-above-driver integration.
Other
43 stars 11 forks source link

Error executing in example/plot_pulse_buffers.py #117

Closed dnolivieri closed 3 months ago

dnolivieri commented 3 months ago

Describe the bug

Given a clean install with conda, using pyhthon 3.9, and install the qat via pip, the following error occurs when executing from command line: python plot_pulse_buffers.py batch_results = self._execute_on_hardware(switerator, qat_file, interrupt) TypeError: _execute_on_hardware() takes 3 positional arguments but 4 were given

Describe what you expected to happen To override the bug, I forced an extra parameter with this function:
def _execute_on_hardware(self, sweep_iterator: SweepIterator, package: QatFile, interrupt=None):

This produces File "/home/david/anaconda3/envs/quant39/lib/python3.9/site-packages/qat/purr/compiler/execution.py", line 448, in create_duration_timeline for instruction in instructions: TypeError: 'QatFile' object is not iterable

Add supporting information

  1. OS/version: Ubuntu: 22.04; conda 2: configuration of qat out of the box on the develop branch; no other changes.
hamidelmaazouz commented 3 months ago

Thank you @dnolivieri,

We'll have a look and circle back.

hamidelmaazouz commented 3 months ago

Hi @dnolivieri,

Regarding this bit, I only see three arguments given to _execute_on_hardware.

batch_results = self._execute_on_hardware(switerator, qat_file, interrupt)
TypeError: _execute_on_hardware() takes 3 positional arguments but 4 were given

It looks to me that _execute_on_hardware wasn't being called properly, could you share contents of your script plot_pulse_buffers.py ?

Thanks,

dnolivieri commented 3 months ago

/Hi Hamid @hamidelmaazouz
Sure, but I didn't do really anything more than what is in the script on the develop branch, with some prints. In order to be able to call the _execute_on_hardware, I added a parameter interrupt=None, so that it would at least get into the function:

def _execute_on_hardware(self, sweep_iterator: SweepIterator, package: QatFile, interrupt=None):
    position_map = self.target.create_duration_timeline(package)
    pulse_buffers = self.target.build_pulse_channel_buffers(
        position_map, do_upconvert=self.upconvert
    )
    buffers = self.target.build_physical_channel_buffers(pulse_buffers)

*** rest of the code the same. if name == "main": qasm = """ OPENQASM 3; include "qelib1.inc"; defcalgrammar "openpulse"; qreg q[2]; creg c[2]; h q[0]; cx q[0],q[1]; measure q -> c;

inside the main block --
hw = get_default_echo_hardware(2) print("HW", hw) parser = Qasm3Parser() builder = parser.parse(get_builder(hw), qasm) print(builder) plot_physical_buffers(builder)

Here is my output: python plot_pulse_buffers.py HW QuantumHardwareModel <qat.purr.compiler.builders.QuantumInstructionBuilder object at 0x7c6b40829e20> Traceback (most recent call last): File "/home/david/Research/repos/qat/examples/plot_pulse_buffers.py", line 129, in plot_physical_buffers(builder) File "/home/david/Research/repos/qat/examples/plot_pulse_buffers.py", line 107, in plot_physical_buffers runtime.execute(builder) File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/runtime.py", line 249, in execute return self._common_execute( File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/runtime.py", line 216, in _common_execute results = fexecute(instructions) File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/runtime.py", line 247, in fexecute return self.engine.execute(instrs) File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/execution.py", line 286, in execute return self._common_execute(instructions) File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/execution.py", line 329, in _common_execute batch_results = self._execute_on_hardware(switerator, qat_file, interrupt) File "/home/david/Research/repos/qat/examples/plot_pulse_buffers.py", line 41, in _execute_on_hardware position_map = self.target.create_duration_timeline(package) File "/home/david/anaconda3/envs/qubit/lib/python3.9/site-packages/qat/purr/compiler/execution.py", line 448, in create_duration_timeline for instruction in instructions: TypeError: 'QatFile' object is not iterable

It seems that the sweep_iterator is not getting through. But, the endpoint to look at this should be in qat/purr/compiler/execution.py.

Dependencies: from pip freeze; here is my install with conda )some fo the relevant ones): qat-compiler==1.1.1 qiskit==0.45.3 qiskit-aer==0.13.3 qiskit-ignis==0.7.1 qiskit-optimization==0.4.0 qiskit-terra==0.45.3 typing_extensions==4.12.2

ld_impl_linux-64 2.38 h1181459_1
libffi 3.4.4 h6a678d5_1
libgcc-ng 11.2.0 h1234567_1
libgomp 11.2.0 h1234567_1
libstdcxx-ng 11.2.0 h1234567_1
python 3.9.18 h955ad1f_0

hamidelmaazouz commented 3 months ago

Thank you @dnolivieri,

TypeError: _execute_on_hardware() takes 3 positional arguments but 4 were given Describe what you expected to happen To override the bug, I forced an extra parameter with this function: def _execute_on_hardware(self, sweep_iterator: SweepIterator, package: QatFile, interrupt=None):

Regarding this issue, I'm not sure how you interacted with the method _execute_on_hardware, I believe the missing parameter is probably because the self object was left out. In any case, this method is an instance private method of PhysicalBufferPlotEngine and it shouldn't be gutted out and run on its own (unless you adjust the arguments list, and other things)

TypeError: 'QatFile' object is not iterable

For this issue you are right. This fix is currently being rolled out. Once it's is merged, you could retry with python $QAT_REPO/examples/plot_pulse_buffers.py.

Thank you for opening a ticket and describing the bug ! Let me know how it goes 😃

Best wishes,

dnolivieri commented 3 months ago

Dear @hamidelmaazouz Thanks so much. Kind regards, David.