garymooney / qmuvi

qMuVi - A python package that converts quantum circuits into audiovisual experiences, bridging the gap between complex quantum computations and human perception. Render music videos that reveal the evolution of quantum states during algorithm processing, making quantum computing more intuitive and accessible.
https://garymooney.github.io/qmuvi/
GNU Lesser General Public License v2.1
14 stars 4 forks source link

Issues with timidity when running qmuvi #40

Open pelahi opened 1 month ago

pelahi commented 1 month ago

Description

When I try running the simple example

import qmuvi
from qiskit import QuantumCircuit

circ = QuantumCircuit(2)
circ.barrier()
circ.h(0)
circ.barrier()
circ.cx(0, 1)
circ.barrier()

qmuvi.generate_qmuvi(circ, "bell_state")

I get the following

Generating qMuVi data...
Generating MIDI track files...
Converting to .wav files using TiMidity++
Errors in thread 0:

And the full error is

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[9], line 11
      8 circ.cx(0, 1)
      9 circ.barrier()
---> 11 qmuvi.generate_qmuvi(circ, "bell_state")

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/__init__.py:164, in generate_qmuvi(quantum_circuit, qmuvi_name, noise_model, rhythm, instruments, note_map, invert_colours, fps, vpr, smooth_transitions, log_to_file, show_measured_probabilities_only, output_dir)
    162 musical_processing.generate_midi_from_data(output_manager, instruments=instruments, note_map=note_map, rhythm=rhythm)
    163 # convert midi files to a wav file
--> 164 musical_processing.convert_midi_to_wav_timidity(output_manager, log_to_file=log_to_file)
    165 # generate video from data
    166 video_generation.generate_video_from_data(
    167     quantum_circuit,
    168     output_manager=output_manager,
   (...)
    174     show_measured_probabilities_only=show_measured_probabilities_only,
    175 )

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:469, in convert_midi_to_wav_timidity(output_manager, timeout, log_to_file)
    466         log.info(thread_results[thread_index].stdout.decode())
    467         log.info(thread_results[thread_index].stderr.decode())
--> 469 convert_files_mid_to_wav_timidity_threading(files, options_string, timidity_convert_subprocess, timeout=timeout)
    471 files = output_manager.glob(output_manager.default_name + "-*.wav")
    472 if len(files) > 1:

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:597, in convert_files_mid_to_wav_timidity_threading(pathnames, options_string, timidity_convert_method, timeout)
    594 if thread_errors[thread_index] is not None:
    595     # an error occured in the thread, show the error
    596     print(f"Errors in thread {thread_index}:")
--> 597     raise thread_errors[thread_index][0]
    599 if thread_result.returncode != 0:
    600     # timidity command failed in subprocess, show subprocess stdout and stderr
    601     print(f"Error from Timidity++ converting file {filename}")

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:456, in convert_midi_to_wav_timidity.<locals>.timidity_convert_subprocess(filename, options_string, thread_results, thread_errors, thread_index)
    453     log.info(f"timidity options: {options_string}")
    454     log.debug(f"executing subprocess command: {command}")
--> 456 thread_results[thread_index] = subprocess.run(command, cwd=package_path, capture_output=True, check=True, shell=shell)
    458 if log_to_file is True:
    459     log.debug("completed subprocess")

File ~/.pyenv/versions/3.9.4/lib/python3.9/subprocess.py:528, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    526     retcode = process.poll()
    527     if check and retcode:
--> 528         raise CalledProcessError(retcode, process.args,
    529                                  output=stdout, stderr=stderr)
    530 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/package_data/binaries/TiMidity-2.15.0/macos/timidity', '-Ow', '--preserve-silence', '-A,120', '--no-anti-alias', '--mod-wheel', '--portamento', '--vibrato', '--no-ch-pressure', '--mod-envelope', '--trace-text-meta', '--overlap-voice', '--default-bank=0', '--default-program=0', '--delay=d,0', '--chorus=n,64', '--reverb=f,40,0.28,0.7,100', '--voice-lpf=c', '--noise-shaping=4', '--resample=5', '--voice-queue=0', '--decay-time=0', '--interpolation=gauss', '-EFresamp=34', '--output-stereo', '--output-24bit', '--polyphony=15887', '--sampling-freq=44100', '--volume-curve=1.661', '--config-file="/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/package_data/resources/timidity/timidity.cfg"', '-o', '"/Users/ela017/myresearch/quantumcomputing/quantum-computing-hackathon/lessons/bell_state-output-1/bell_state-4.wav"', '"/Users/ela017/myresearch/quantumcomputing/quantum-computing-hackathon/lessons/bell_state-output-1/bell_state-4.mid"']' returned non-zero exit status 1.

If I try running this command (ignoring the output) from timidity I get

Try timidity -h for help

And it's version is

TiMidity++ version 2.15.0

Copyright (C) 1999-2018 Masanao Izumo <iz@onicos.co.jp>
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

It is not clear what the issue might be (if it is a conflict in the version of timidity wrt instruction set produced by qmuvi) but I am unable to produce the expected audio output.

Gary if you have some suggestions I'd be happy to try them.

garymooney commented 1 month ago

Hi Pelahi,

That is strange, thanks for letting me know. I don't have a mac atm, so it's a little hard for me to check.

Could you please try setting log_to_file=True in the generate_qmuvi method and send me one of the generated log files.

pelahi commented 1 month ago

Hi Gary, Here's the extra output .

Generating qMuVi data...
Generating MIDI track files...

Exception in thread Exception in thread timidity-1:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-3:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-2:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-0:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-6:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-5:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
timidity-4:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
Exception in thread timidity-7:
Traceback (most recent call last):
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self.run()
  File "/Users/ela017/.pyenv/versions/3.9.4/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    self._target(*self._args, **self._kwargs)
  File "/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py", line 466, in timidity_convert_subprocess
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
        log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'
    log.info(thread_results[thread_index].stdout.decode())
AttributeError: 'NoneType' object has no attribute 'stdout'

Converting to .wav files using TiMidity++
Errors in thread 0:

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[10], line 11
      8 circ.cx(0, 1)
      9 circ.barrier()
---> 11 qmuvi.generate_qmuvi(circ, "bell_state", log_to_file=True)

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/__init__.py:164, in generate_qmuvi(quantum_circuit, qmuvi_name, noise_model, rhythm, instruments, note_map, invert_colours, fps, vpr, smooth_transitions, log_to_file, show_measured_probabilities_only, output_dir)
    162 musical_processing.generate_midi_from_data(output_manager, instruments=instruments, note_map=note_map, rhythm=rhythm)
    163 # convert midi files to a wav file
--> 164 musical_processing.convert_midi_to_wav_timidity(output_manager, log_to_file=log_to_file)
    165 # generate video from data
    166 video_generation.generate_video_from_data(
    167     quantum_circuit,
    168     output_manager=output_manager,
   (...)
    174     show_measured_probabilities_only=show_measured_probabilities_only,
    175 )

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:469, in convert_midi_to_wav_timidity(output_manager, timeout, log_to_file)
    466         log.info(thread_results[thread_index].stdout.decode())
    467         log.info(thread_results[thread_index].stderr.decode())
--> 469 convert_files_mid_to_wav_timidity_threading(files, options_string, timidity_convert_subprocess, timeout=timeout)
    471 files = output_manager.glob(output_manager.default_name + "-*.wav")
    472 if len(files) > 1:

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:597, in convert_files_mid_to_wav_timidity_threading(pathnames, options_string, timidity_convert_method, timeout)
    594 if thread_errors[thread_index] is not None:
    595     # an error occured in the thread, show the error
    596     print(f"Errors in thread {thread_index}:")
--> 597     raise thread_errors[thread_index][0]
    599 if thread_result.returncode != 0:
    600     # timidity command failed in subprocess, show subprocess stdout and stderr
    601     print(f"Error from Timidity++ converting file {filename}")

File ~/software/pyvenv/lib/python3.9/site-packages/qmuvi/musical_processing.py:456, in convert_midi_to_wav_timidity.<locals>.timidity_convert_subprocess(filename, options_string, thread_results, thread_errors, thread_index)
    453     log.info(f"timidity options: {options_string}")
    454     log.debug(f"executing subprocess command: {command}")
--> 456 thread_results[thread_index] = subprocess.run(command, cwd=package_path, capture_output=True, check=True, shell=shell)
    458 if log_to_file is True:
    459     log.debug("completed subprocess")

File ~/.pyenv/versions/3.9.4/lib/python3.9/subprocess.py:528, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    526     retcode = process.poll()
    527     if check and retcode:
--> 528         raise CalledProcessError(retcode, process.args,
    529                                  output=stdout, stderr=stderr)
    530 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/package_data/binaries/TiMidity-2.15.0/macos/timidity', '-Ow', '--verbose=3', '--preserve-silence', '-A,120', '--no-anti-alias', '--mod-wheel', '--portamento', '--vibrato', '--no-ch-pressure', '--mod-envelope', '--trace-text-meta', '--overlap-voice', '--default-bank=0', '--default-program=0', '--delay=d,0', '--chorus=n,64', '--reverb=f,40,0.28,0.7,100', '--voice-lpf=c', '--noise-shaping=4', '--resample=5', '--voice-queue=0', '--decay-time=0', '--interpolation=gauss', '-EFresamp=34', '--output-stereo', '--output-24bit', '--polyphony=15887', '--sampling-freq=44100', '--volume-curve=1.661', '--config-file="/Users/ela017/software/pyvenv/lib/python3.9/site-packages/qmuvi/package_data/resources/timidity/timidity.cfg"', '-o', '"/Users/ela017/myresearch/quantumcomputing/quantum-computing-hackathon/lessons/bell_state-output-2/bell_state-4.wav"', '"/Users/ela017/myresearch/quantumcomputing/quantum-computing-hackathon/lessons/bell_state-output-2/bell_state-4.mid"']' returned non-zero exit status 1.