Skip to content
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

Default measurement for annealing for the first demo implementation. #778

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
543da5e
add parameter class and one qubit analog transpiler
visagim Aug 1, 2024
6c3a0f6
add unit tests
visagim Aug 1, 2024
d3f70db
Merge branch 'main' into add-one-qubit-analog-transpiler
visagim Aug 1, 2024
eb9da50
Merge branch 'main' into add-one-qubit-analog-transpiler
visagim Aug 1, 2024
5bb6efc
add unit tests
visagim Aug 1, 2024
e39bc13
Merge branch 'add-one-qubit-analog-transpiler' of https://github.com/…
visagim Aug 1, 2024
57bbf9c
move fluqe parameter inside analog, fix pylint complains
visagim Aug 1, 2024
1c07db7
draft of anneal program with transpiler for 1q
visagim Aug 1, 2024
c9f49d8
add analog program execution workflow
visagim Aug 6, 2024
95970f9
merge main
visagim Aug 6, 2024
d5543d3
add changelog
visagim Aug 6, 2024
a2a0bec
fix mypy
visagim Aug 7, 2024
aa52461
fix docstring
visagim Aug 7, 2024
6527d4c
add unit test for anneal program
visagim Aug 7, 2024
81bb027
wip platform unit tests
visagim Aug 8, 2024
9b29997
add to_dict method to qprogram in order to tests that a qprogram is e…
visagim Aug 8, 2024
e6fb8d6
Merge branch 'main' into create-annealingSchedule-class/QHC-636
visagim Aug 9, 2024
fc6eb65
Merge branch 'main' into create-annealingSchedule-class/QHC-636
visagim Aug 9, 2024
8ad0457
fix tests
visagim Aug 11, 2024
12e0cca
Merge branch 'create-annealingSchedule-class/QHC-636' of https://gith…
visagim Aug 11, 2024
2c24f26
Merge branch 'main' into create-annealingSchedule-class/QHC-636
visagim Aug 11, 2024
67d3145
fix pylint
visagim Aug 11, 2024
cf1cdab
Merge branch 'create-annealingSchedule-class/QHC-636' of https://gith…
visagim Aug 11, 2024
3693bd1
fix docstrings, pylint
visagim Aug 11, 2024
b499fcf
still trying to fix docs
visagim Aug 11, 2024
6e14382
still trying to fix the docs
visagim Aug 11, 2024
037aa23
still trying to fix the docs
visagim Aug 11, 2024
2648b30
still trying to fix the docs
visagim Aug 11, 2024
a73de8b
change qprogram to_readable_dict to __str__ method
visagim Aug 12, 2024
3999c71
fix tests, fix docs
visagim Aug 12, 2024
914f568
add suggested changes
visagim Aug 12, 2024
930b56e
add unittest for qprogram str method
visagim Aug 12, 2024
3a5c9f7
fix tests
visagim Aug 12, 2024
f297827
remove unused import
visagim Aug 12, 2024
304cc6c
fix coverage
visagim Aug 12, 2024
6bc760d
update changelog
visagim Aug 12, 2024
eb7373f
Merge branch 'main' into create-annealingSchedule-class/QHC-636
visagim Aug 14, 2024
af70254
Merge branch 'main' into create-annealingSchedule-class/QHC-636
visagim Aug 14, 2024
5bea2a3
implementation proposal
actions-user Aug 19, 2024
6544242
code quality
actions-user Aug 19, 2024
7f0b70d
testing annealing
actions-user Aug 19, 2024
17c7540
weights are optional
actions-user Aug 19, 2024
d460846
raising error
actions-user Aug 19, 2024
682e2c0
raises error test
actions-user Aug 19, 2024
ef2ceb2
QHC 621 Modify set_intermediate_frequency for the jobAPI (#764)
jordivallsq Aug 16, 2024
af7acec
tests
actions-user Aug 19, 2024
79dd475
isort
actions-user Aug 19, 2024
e139c8d
measure in test
actions-user Aug 19, 2024
fd79f53
code quality
actions-user Aug 19, 2024
8ca635e
code quality
actions-user Aug 19, 2024
9f5d37e
removing duplicate fixture
actions-user Aug 19, 2024
a548410
removing duplicate
actions-user Aug 19, 2024
792e2e8
disabling too many lines in platform
actions-user Aug 19, 2024
b64839c
removing unused arguments
actions-user Aug 19, 2024
76f66a5
calibration fixture
actions-user Aug 19, 2024
a783967
code quality
actions-user Aug 19, 2024
a0c3df5
fixing unittest
actions-user Aug 19, 2024
070a323
removing brackets typo
actions-user Aug 19, 2024
d291709
passing by calibration to execute_qprogram
actions-user Aug 19, 2024
cf97c85
refactoring
actions-user Aug 19, 2024
25feb1d
fixing unittest
actions-user Aug 19, 2024
02f1c26
removing comment
actions-user Aug 19, 2024
42b769f
Merge branch 'main' into qhc-691-add-default-measurement-pulse-to-ann…
jjmartinezQT Aug 19, 2024
582a8e1
[QHC-636] Create AnnealingSchedule class in Qililab. (#767)
visagim Aug 21, 2024
5848a89
changelog
actions-user Aug 21, 2024
b4930ab
Merge branch 'main' into qhc-691-add-default-measurement-pulse-to-ann…
jjmartinezQT Aug 21, 2024
eac6e65
code quality
actions-user Aug 21, 2024
76d068a
returning results of annealing
actions-user Aug 21, 2024
de69b25
returning type
actions-user Aug 21, 2024
e7a1313
code quality
actions-user Aug 21, 2024
da0e8e4
making calibration file non optional
actions-user Aug 21, 2024
88a2444
introducing sync
actions-user Aug 21, 2024
f0e5ed7
code quality
actions-user Aug 21, 2024
07eedc3
code quality
actions-user Aug 21, 2024
3b9d342
outside loop
actions-user Aug 21, 2024
e642b00
checking type
actions-user Aug 21, 2024
3f1a623
changing test
actions-user Aug 21, 2024
2d320cf
adding calibration
actions-user Aug 21, 2024
3343dce
fixing unittest
actions-user Aug 21, 2024
5b9fb98
checking return type
actions-user Aug 21, 2024
8337c7c
removing src
actions-user Aug 21, 2024
ff99bea
Merge branch 'main' into qhc-691-add-default-measurement-pulse-to-ann…
jjmartinezQT Aug 21, 2024
3cd61fd
code quality
actions-user Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/releases/changelog-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### New features since last release

- Add default measurement to `execute_anneal_program()` method. This method takes now a calibration file and parameters
to add the dispersive measurement at the end of the annealing schedule.
[#778](https://github.com/qilimanjaro-tech/qililab/pull/778)

- Add `__str__` method to qprogram. The string is a readable qprogram.
[#767](https://github.com/qilimanjaro-tech/qililab/pull/767)

Expand Down
45 changes: 31 additions & 14 deletions src/qililab/platform/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=too-many-lines
jjmartinezQT marked this conversation as resolved.
Show resolved Hide resolved
"""Platform class."""
import ast
import io
Expand Down Expand Up @@ -51,6 +52,7 @@
from qililab.system_control import ReadoutSystemControl
from qililab.typings.enums import InstrumentName, Line, Parameter
from qililab.utils import hash_qpy_sequence
from qililab.waveforms import IQPair, Square

from .components import Bus, Buses

Expand Down Expand Up @@ -600,10 +602,16 @@ def __str__(self) -> str:
"""
return str(YAML().dump(self.to_dict(), io.BytesIO()))

# TODO: determine default average
def execute_anneal_program(
self, annealing_program_dict: list[dict[str, dict[str, float]]], transpiler: Callable, averages=1
):
self,
annealing_program_dict: list[dict[str, dict[str, float]]],
calibration: Calibration,
readout_bus: str,
measurement_name: str,
transpiler: Callable,
averages=1,
weights: str | None = None,
) -> QProgramResults:
"""Given an annealing program execute it as a qprogram.
The annealing program should contain a time ordered list of circuit elements and their corresponging ising coefficients as a dictionary. Example structure:

Expand All @@ -627,18 +635,27 @@ def execute_anneal_program(
transpiler (Callable): ising to flux transpiler. The transpiler should take 2 values as arguments (delta, epsilon) and return 2 values (phix, phiz)
averages (int, optional): Amount of times to run and average the program over. Defaults to 1.
"""
annealing_program = AnnealingProgram(self, annealing_program_dict)
annealing_program.transpile(transpiler)
annealing_waveforms = annealing_program.get_waveforms()

qp_annealing = QProgram()
with qp_annealing.average(averages):
for bus, waveform in annealing_waveforms.values():
qp_annealing.play(bus=bus.alias, waveform=waveform)

# TODO: define readout
if calibration.has_waveform(bus=readout_bus, name=measurement_name):
annealing_program = AnnealingProgram(self, annealing_program_dict)
annealing_program.transpile(transpiler)
annealing_waveforms = annealing_program.get_waveforms()

qp_annealing = QProgram()
with qp_annealing.average(averages):
for bus, waveform in annealing_waveforms.values():
qp_annealing.play(bus=bus.alias, waveform=waveform)
qp_annealing.sync()
if weights and calibration.has_weights(bus=readout_bus, name=weights):
qp_annealing.measure(bus=readout_bus, waveform=measurement_name, weights=weights)
else:
r_duration = calibration.get_waveform(bus=readout_bus, name=measurement_name).get_duration()
weights_shape = Square(amplitude=1, duration=r_duration)
qp_annealing.measure(
bus=readout_bus, waveform=measurement_name, weights=IQPair(I=weights_shape, Q=weights_shape)
)

self.execute_qprogram(qprogram=qp_annealing)
return self.execute_qprogram(qprogram=qp_annealing, calibration=calibration)
raise ValueError("The calibrated measurement is not present in the calibration file.")

def execute_qprogram( # pylint: disable=too-many-locals
self,
Expand Down
76 changes: 70 additions & 6 deletions tests/platform/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
from qililab.instruments.quantum_machines import QuantumMachinesCluster
from qililab.platform import Bus, Buses, Platform
from qililab.pulse import Drag, Pulse, PulseEvent, PulseSchedule, Rectangular
from qililab.qprogram import QProgram
from qililab.qprogram import Calibration, QProgram
from qililab.result.qblox_results import QbloxResult
from qililab.result.qprogram.qprogram_results import QProgramResults
from qililab.result.qprogram.quantum_machines_measurement_result import QuantumMachinesMeasurementResult
from qililab.settings import Runcard
from qililab.settings.gate_event_settings import GateEventSettings
Expand Down Expand Up @@ -109,6 +110,23 @@ def fixture_qblox_results():
]


@pytest.fixture(name="calibration")
def get_calibration():
readout_duration = 2000
readout_amplitude = 1.0
r_wf_I = Square(amplitude=readout_amplitude, duration=readout_duration)
r_wf_Q = Square(amplitude=0.0, duration=readout_duration)
readout_waveform = IQPair(I=r_wf_I, Q=r_wf_Q)
weights_shape = Square(amplitude=1, duration=readout_duration)
weights = IQPair(I=weights_shape, Q=weights_shape)

calibration = Calibration()
calibration.add_waveform(bus="readout_bus", name="readout", waveform=readout_waveform)
calibration.add_weights(bus="readout_bus", name="optimal_weights", weights=weights)

return calibration


@pytest.fixture(name="anneal_qprogram")
def get_anneal_qprogram(runcard):
platform = Platform(runcard=runcard)
Expand All @@ -127,10 +145,19 @@ def get_anneal_qprogram(runcard):
),
}
averages = 2
readout_duration = 2000
readout_amplitude = 1.0
r_wf_I = Square(amplitude=readout_amplitude, duration=readout_duration)
r_wf_Q = Square(amplitude=0.0, duration=readout_duration)
readout_waveform = IQPair(I=r_wf_I, Q=r_wf_Q)
weights_shape = Square(amplitude=1, duration=readout_duration)
weights = IQPair(I=weights_shape, Q=weights_shape)
qp_anneal = QProgram()
with qp_anneal.average(averages):
for bus, waveform in anneal_waveforms.values():
qp_anneal.play(bus=bus.alias, waveform=waveform)
qp_anneal.sync()
qp_anneal.measure(bus="readout_bus", waveform=readout_waveform, weights=weights)
return qp_anneal


Expand Down Expand Up @@ -375,16 +402,53 @@ def _compile_and_assert(self, platform: Platform, program: Circuit | PulseSchedu
assert all(isinstance(sequence, Sequence) for sequence in sequences_list)
assert sequences_list[0]._program.duration == 200_000 * 1000 + 4 + 4 + 4

def test_execute_anneal_program(self, platform: Platform, anneal_qprogram):
def test_execute_anneal_program(self, platform: Platform, anneal_qprogram, calibration):
mock_execute_qprogram = MagicMock()
mock_execute_qprogram.return_value = QProgramResults()
platform.execute_qprogram = mock_execute_qprogram # type: ignore[method-assign]
transpiler = MagicMock()
transpiler.return_value = (1, 2)
# with patch(qililab.analog.annealing_program, "AnnealingProgram") as dummy_anneal_program:
platform.execute_anneal_program(
annealing_program_dict=[{"qubit_0": {"sigma_x": 0.1, "sigma_z": 0.2}}], transpiler=transpiler, averages=2

results = platform.execute_anneal_program(
annealing_program_dict=[{"qubit_0": {"sigma_x": 0.1, "sigma_z": 0.2}}],
transpiler=transpiler,
averages=2,
readout_bus="readout_bus",
measurement_name="readout",
weights="optimal_weights",
calibration=calibration,
)
qprogram = mock_execute_qprogram.call_args[1]["qprogram"].with_calibration(calibration)
assert str(anneal_qprogram) == str(qprogram)
assert isinstance(results, QProgramResults)

results = platform.execute_anneal_program(
annealing_program_dict=[{"qubit_0": {"sigma_x": 0.1, "sigma_z": 0.2}}],
transpiler=transpiler,
averages=2,
readout_bus="readout_bus",
measurement_name="readout",
calibration=calibration,
)
assert str(anneal_qprogram) == str(mock_execute_qprogram.call_args[1]["qprogram"])
qprogram = mock_execute_qprogram.call_args[1]["qprogram"].with_calibration(calibration)
assert str(anneal_qprogram) == str(qprogram)
assert isinstance(results, QProgramResults)

def test_execute_anneal_program_no_measurement_raises_error(self, platform: Platform, calibration):
mock_execute_qprogram = MagicMock()
platform.execute_qprogram = mock_execute_qprogram # type: ignore[method-assign]
transpiler = MagicMock()
transpiler.return_value = (1, 2)
error_string = "The calibrated measurement is not present in the calibration file."
with pytest.raises(ValueError, match=error_string):
platform.execute_anneal_program(
annealing_program_dict=[{"qubit_0": {"sigma_x": 0.1, "sigma_z": 0.2}}],
transpiler=transpiler,
averages=2,
readout_bus="readout_bus",
measurement_name="whatever",
calibration=calibration,
)

def test_execute_qprogram_with_qblox(self, platform: Platform):
"""Test that the execute method compiles the qprogram, calls the buses to run and return the results."""
Expand Down
Loading