Skip to content

Conversation

@yaelbh
Copy link
Collaborator

@yaelbh yaelbh commented Nov 9, 2021

Users will not be able to determine the units of their input parameters. When it comes to time units, pulse widths will be in dt, and delays as in T1 and T2 will be in seconds.

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yaelbh for taking a look at the unit issue. I think there are several other experiments that take frequency val with arbitrary unit. Probably we need an internal rule to define how we pass values to fitter, either dt or SI. If fitter assumes values in SI the xval conversion logic should exist on experiment side.

"experiment_type": self.experiment_type,
"qubits": self.physical_qubits,
"xval": prefactor * flat_top_width * dt_factor, # in units of sec
"xval": flat_top_width
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this conversion is necessary because fitter assumes xval in sec, i.e. it need to compute Hamiltonian coefficients in Hz (or you can covert dt in sec in the fitter since it still has access to backend)

@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 10, 2021

To do:

  • Update the characterization experiments: CR Hamitonian, Ramsey XY, T1, T2Ramsey.
  • Fix their tests.
  • Fix their tutorials.
  • Do the same for calibration units that are different from Hz (like kHz and MHz) ?
  • Release notes.

options.normalization = True
options.xlabel = "Frequency"
options.ylabel = "Signal (arb. units)"
options.xval_unit = "Hz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this xval_unit is necessary because this represents an axis label of output figure.

@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 16, 2021

I'd like not to update the cloud tutorial. It's not updated to the latest main in the first place, it involves cuts of screenshots from the web, and is about to be refactored anyway.

@yaelbh yaelbh changed the title [WIP] Remove units from experiment options Remove units from experiment options Nov 16, 2021
Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yaelbh this is really good. Just one request for update of handling of delay to be more precise. You can also remove this code
https://github.com/Qiskit/qiskit-experiments/blob/482a83cede9a22fd96bfa176446014d48e57ea61/qiskit_experiments/library/characterization/t1.py#L108-L118
and
https://github.com/Qiskit/qiskit-experiments/blob/482a83cede9a22fd96bfa176446014d48e57ea61/qiskit_experiments/library/characterization/t1.py#L64
because this exist because of init guess unit conversion that is removed with this PR. Then you can revert the patch code introduced in #529


circuits = []
for delay in prefactor * np.asarray(self.experiment_options.delays, dtype=float):
for delay in np.asarray(self.experiment_options.delays, dtype=float):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we explicitly convert delay into dt here? Because delay in SI is converted into dt in the transpiler and rounded to integer. So actual delay value can differ from x value in analysis by this rounded value. This effect becomes visible when T1 value is very short (really edge case though).

The code is something like

delay_dt = int(np.round(delay / dt_factor))
...

circ.delay(delay_dt, 0, "dt")
...

    "xval": delay_dt * dt_factor,

same for T2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. On the one hand, I understand your reason. On the other hand:

  1. I was hoping to completely get rid of anything that has units and factors in it.
  2. Users may not understand why the delays they entered have shifted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree mismatch due to rounding error is negligible and probably this is overkill. In our device, the error of actual delay and fit xval is less than 0.22 ns which is way smaller than T1 decay of fit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the values should be shifted, but I also agree that for current IBM devices this concern is negligible for T1. However, there are some experiments where timing is important and I think we should try to handle time values consistently across experiments. So I think it would be best to store time values as the real values when we are scanning time and rounding is involved. Maybe a helper function for translating the time values could help promote handling time values consistently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but in way that's a bit different from the one suggested here, please check

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks okay to me, but @nkanazawa1989 should check it. I don't know what one can rely on when doing a transpilation. Could a delay gate ever be split into multiple delays or could another delay gate ever get inserted in the beginning of a circuit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too hacky and has several edge cases. For example, you only assumes single delay in the program but this is not true because measure align pass will add extra delay before measurement to align acquire instruction. In addition, T2Ramsey needs delay to insert artificial rotation and the rotation angle should be computed with correct delay amount. Of course calling transpile for computing xval is too much extra computation overhead. Why just cannot

delays_dt = np.round(options.delays / self.backend.configuration().dt).astype(int)

for delay_dt in delays_dt:
    delay_sec_rounded = delay_dt * self.backend.configuration().dt  # used for T2Ramsey and xval
    qc.delay(delay_dt, 0, "dt")

Indeed this is what is done during transpilation.

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are still skeptical, you can call this function from terra. This is what exactly called when you transpile delays with value in sec (but warnings are super annoying).
https://github.com/Qiskit/qiskit-terra/blob/f6ab3a98ca2c8c33842e1adbf5da6fbde78dc268/qiskit/circuit/duration.py#L23-L42

yaelbh and others added 2 commits November 21, 2021 08:40
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
@yaelbh
Copy link
Collaborator Author

yaelbh commented Nov 21, 2021

Reporting that I was able to successfully run on a device and save to the database.

@yaelbh yaelbh requested a review from nkanazawa1989 November 25, 2021 12:10

circuits = []
for delay in self.experiment_options.delays:
rotation_angle = 2 * np.pi * self.experiment_options.osc_freq * delay
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update delay here (will be delay_dt * dt_factor)

@yaelbh yaelbh requested a review from nkanazawa1989 November 28, 2021 07:44
@yaelbh yaelbh mentioned this pull request Nov 29, 2021
@yaelbh yaelbh linked an issue Nov 29, 2021 that may be closed by this pull request
delay = np.round(delay, decimals=10)
for delay in self.experiment_options.delays:
if dt_unit:
real_delay_in_sec = delay_dt * dt_factor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like delay_dt is used before assignment. how is this test passed? seems like we are testing only on the backend without dt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is how we test, but I always run on a device and look at the results, so I can't explain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I can explain: I've had other, unrelated problems with T2Ramsey-on-device lately, in the main branch, I think I opened issues. So I didn't run.

ram_x = self._pre_circuit()
ram_x.sx(0)
ram_x.delay(p_delay, 0, self.experiment_options.unit)
ram_x.delay(p_delay, 0, "s")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please also update this in the same way with t2ramsey?

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yaelbh I'll approve with update of RamseyXY.

@nkanazawa1989 nkanazawa1989 added this to the Release 0.2 milestone Dec 8, 2021
@nkanazawa1989
Copy link
Collaborator

This is API change and should be merged in 0.2. Any update? @yaelbh ? I found that we should set delay in units "dt" rather than "s" for T1, T2Ramsey, RamseyXY to avoid annoying user warning.

image

Could you please update the logic?

@yaelbh
Copy link
Collaborator Author

yaelbh commented Dec 9, 2021

@nkanazawa1989 I haven't tested on device yet (I'm going to do it now) but essentially it's ready. In ramsey xy I had to work with two parameters because Parameter doesn't support round and int operations (working only with one parameter, there was an error that delay unit in dt must be integer).

Copy link
Collaborator

@nkanazawa1989 nkanazawa1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Yael. Code looks good to me. Probably we need to implement some logic to allow typecast of Parameter in future (I had same problem when I write CR ham tomo).

@yaelbh yaelbh merged commit a6f1f67 into qiskit-community:main Dec 9, 2021
@yaelbh yaelbh deleted the units branch December 9, 2021 09:29
paco-ri pushed a commit to paco-ri/qiskit-experiments that referenced this pull request Jul 11, 2022
* dt units in cr_hamiltonian

* updated characterization experiments

* t1 tests

* t2ramsey test

* cr hamiltonian tests

* Ramsey XY tests

* black

* lint

* fixed ramsey xy test

* Hz

* black

* lint

* updated t1 tutorial

* lint

* fixed tests

* t1 tutorial again (nicer execution count)

* updated t2 ramsey tutorial

* more update to t2ramsey tutorial

* fixed analysis option in qubit spectro

* release notes

* Update qiskit_experiments/library/calibration/rough_frequency.py

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* Update releasenotes/notes/remove-units-78db311686213a58.yaml

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>

* update xval to the true value following transpilation and conversion to dt

* round dts

* fixed rotation angle in t2ramsey

* bug fix in t2ramsey

* resolved conflict

* ramsey_xy

* transpile options for ramsey xy

Co-authored-by: Naoki Kanazawa <nkanazawa1989@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Revisit units in API

3 participants