-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arraylias integration - Signal class - #269
Arraylias integration - Signal class - #269
Conversation
@@ -728,6 +738,7 @@ def test_conjugate(self): | |||
) | |||
|
|||
|
|||
@partial(test_array_backends, array_libraries=["numpy", "jax", "array_numpy", "array_jax"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This decorator works as creating TestDiscreteSignalSum of "numpy", "jax", "array_numpy", "array_jax", which inherits TestSignalSum. But there is no class whose name is TestSignalSum because it has already been decorated by test_array_backends.
potential fix for using test_array_backends
The current implementation fails the tutorial in optimizing_pulse_sequence.rst. The main reason for this failure is that
if isinstance(signal, DiscreteSignal):
# Perform a discrete time convolution.
dt = signal.dt
func_samples = np.asarray([self._func(dt * i) for i in range(signal.duration)])
func_samples = func_samples / sum(func_samples)
sig_samples = signal(dt * np.arange(signal.duration)) even if np -> unp is changed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signals
and test/dynamics/signals
folders look good to me aside from the two comments I made:
- change
alias
tonumpy_alias
- Remove all redundant type hinting for "numbers" and
List
whereArrayLike
appears.
qiskit_dynamics/signals/signals.py
Outdated
from qiskit import QiskitError | ||
from qiskit_dynamics.array import Array | ||
from qiskit_dynamics.arraylias import ArrayLike | ||
from qiskit_dynamics.arraylias import DYNAMICS_NUMPY_ALIAS as alias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe we should call this numpy_alias
instead of just alias
now that there will be one for NumPy and one for SciPy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at 79c45ce .
qiskit_dynamics/signals/signals.py
Outdated
envelope: Union[Callable, complex, float, int, ArrayLike], | ||
carrier_freq: Union[float, List, ArrayLike] = 0.0, | ||
phase: Union[float, List, ArrayLike] = 0.0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type hints are redundant as ArrayLike
includes float
, int
, complex
. Should we remove everything but ArrayLike
here?
I see ArrayLike
doesn't include List
, but maybe we should add that, as it does technically act on lists as well.
Edit: Ah yes I see later on in the file for DiscreteSignalSum
you do conversions like Union[float, List, ArrayLike]
-> ArrayLike
. This should be done for all similar type hints throughout the whole file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to figure out how to get the tests to pass in other submodules - the issue with a lot of the failures seems to be that:
ends up calling This issue comes up in tests like
This test (and I'm guessing many others) can be fixed by simply changing the above to:
This is how we'll want to do things going forward anyway, but this doesn't help with the fact that Fixing this by modifying |
I've figured out how to bypass the above issue and directly fix most tests here. The only thing I haven't fixed yet is stuff to do with pulse -> signal conversion and JAX compatibility - but I think it may just be the same issue. I'll attempt again to see if we can "properly" fix this problem (i.e. get |
05f651d
to
591b533
Compare
The tests which have not been passed are two types:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All looking good to me, but some final nitpicking details to sort out.
qiskit_dynamics/signals/signals.py
Outdated
samples = unp.append(sig1.samples, sig2.samples, axis=1) | ||
carrier_freq = unp.append(sig1.carrier_freq, sig2.carrier_freq) | ||
phase = unp.append(sig1.phase, sig2.phase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect these lines may be prone to the dispatching errors we had to deal with in other places. Should these be changed to use _numpy_multi_dispatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot to change it to _numpy_multi_dispatch
.
I fixed at 2e1436e.
qiskit_dynamics/signals/signals.py
Outdated
0.5 | ||
* (sig1.samples[:, :, None] * sig2.samples[:, None, :].conj()).reshape( | ||
(sig1.samples.shape[0], sig1.samples.shape[1] * sig2.samples.shape[1]), | ||
order="C", | ||
) | ||
) | ||
samples = np.append(new_samples, new_samples_conj, axis=1) | ||
samples = unp.append(new_samples, new_samples_conj, axis=1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_numpy_multi_dispatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed at 2e1436e.
qiskit_dynamics/signals/signals.py
Outdated
|
||
new_freqs = sig1.carrier_freq + sig2.carrier_freq | ||
new_freqs_conj = sig1.carrier_freq - sig2.carrier_freq | ||
freqs = np.append(Array(new_freqs), Array(new_freqs_conj)) | ||
freqs = unp.append(unp.asarray(new_freqs), unp.asarray(new_freqs_conj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_numpy_multi_dispatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed at 2e1436e.
qiskit_dynamics/signals/signals.py
Outdated
|
||
new_phases = sig1.phase + sig2.phase | ||
new_phases_conj = sig1.phase - sig2.phase | ||
phases = np.append(Array(new_phases), Array(new_phases_conj)) | ||
phases = unp.append(unp.asarray(new_phases), unp.asarray(new_phases_conj)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_numpy_multi_dispatch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed at 2e1436e.
Co-authored-by: Daniel Puzzuoli <[email protected]>
Co-authored-by: Daniel Puzzuoli <[email protected]>
Co-authored-by: Daniel Puzzuoli <[email protected]>
Co-authored-by: Daniel Puzzuoli <[email protected]>
Co-authored-by: Daniel Puzzuoli <[email protected]>
Summary
I started to integrate arraylias to dynamics.
This PR includes the integration of the Signal class in dynamics.
Details and comments