lca_index
int64
0
223
idx
stringlengths
7
11
line_type
stringclasses
6 values
ground_truth
stringlengths
2
35
completions
sequencelengths
3
1.16k
prefix
stringlengths
298
32.8k
postfix
stringlengths
0
28.6k
repo
stringclasses
34 values
216
216-169-17
random
ref_pd_df_by_series_only_index
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_df_index_with_df", "test_add_df_index_with_none", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.
, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-176-13
inproject
data
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_data_frame_index_with_df", "test_add_data_frame_index_with_none", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.
.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-176-18
inproject
add_data_frame_index
[ "add_data_frame", "add_data_frame_index", "add_df", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "build", "clear", "copy", "dump", "filter", "from_json", "fromkeys", "get", "items", "keys", "pop", "popitem", "set_filter", "setdefault", "update", "values", "_add_named_value", "_add_value", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.
(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-184-13
inproject
data
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_data_frame_index_with_df", "test_add_data_frame_index_with_none", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.
.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-184-18
inproject
add_data_frame_index
[ "add_data_frame", "add_data_frame_index", "add_df", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "build", "clear", "copy", "dump", "filter", "from_json", "fromkeys", "get", "items", "keys", "pop", "popitem", "set_filter", "setdefault", "update", "values", "_add_named_value", "_add_value", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.
(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-193-13
inproject
data
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_df_index_with_series", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.
.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-193-18
inproject
add_df_index
[ "add_data_frame", "add_data_frame_index", "add_df", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "build", "clear", "copy", "dump", "filter", "from_json", "fromkeys", "get", "items", "keys", "pop", "popitem", "set_filter", "setdefault", "update", "values", "_add_named_value", "_add_value", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.
( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-194-17
random
in_pd_series_dimension_with_index
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_df_index_with_series", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.
, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-203-17
inproject
data
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_df_index_with_series", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.
.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-203-22
inproject
build
[ "add_data_frame", "add_data_frame_index", "add_df", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "build", "clear", "copy", "dump", "filter", "from_json", "fromkeys", "get", "items", "keys", "pop", "popitem", "set_filter", "setdefault", "update", "values", "_add_named_value", "_add_value", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.
(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-209-13
inproject
data
[ "addClassCleanup", "addCleanup", "addTypeEqualityFunc", "assert_", "assertAlmostEqual", "assertAlmostEquals", "assertCountEqual", "assertDictContainsSubset", "assertDictEqual", "assertEqual", "assertEquals", "assertFalse", "assertGreater", "assertGreaterEqual", "assertIn", "assertIs", "assertIsInstance", "assertIsNone", "assertIsNot", "assertIsNotNone", "assertLess", "assertLessEqual", "assertListEqual", "assertLogs", "assertMultiLineEqual", "assertNotAlmostEqual", "assertNotAlmostEquals", "assertNotEqual", "assertNotEquals", "assertNotIn", "assertNotIsInstance", "assertNotRegex", "assertNotRegexpMatches", "assertRaises", "assertRaisesRegex", "assertRaisesRegexp", "assertRegex", "assertRegexpMatches", "assertSequenceEqual", "assertSetEqual", "assertTrue", "assertTupleEqual", "assertWarns", "assertWarnsRegex", "asset_dir", "countTestCases", "data", "debug", "defaultTestResult", "doClassCleanups", "doCleanups", "fail", "failIf", "failIfAlmostEqual", "failIfEqual", "failUnless", "failUnlessAlmostEqual", "failUnlessEqual", "failUnlessRaises", "failureException", "id", "in_pd_df_by_series", "in_pd_df_by_series_with_duplicated_popularity", "in_pd_df_by_series_with_index", "in_pd_df_by_series_with_nan", "in_pd_series_dimension", "in_pd_series_dimension_with_index", "in_pd_series_dimension_with_nan", "in_pd_series_measure", "in_pd_series_measure_with_index", "in_pd_series_measure_with_nan", "longMessage", "maxDiff", "ref_pd_df_by_series", "ref_pd_df_by_series_max_rows", "ref_pd_df_by_series_only_index", "ref_pd_df_by_series_with_duplicated_popularity", "ref_pd_df_by_series_with_index", "ref_pd_df_by_series_with_nan", "ref_pd_series", "ref_pd_series_only_index", "ref_pd_series_with_index", "ref_pd_series_with_nan", "run", "set_up_pd_df", "set_up_pd_series", "setUp", "setUpClass", "shortDescription", "skipTest", "subTest", "tearDown", "tearDownClass", "test_add_data_frame_index_with_series", "_addSkip", "_formatMessage", "_getAssertEqualityFunc", "_testMethodDoc", "_testMethodName", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.
.add_data_frame_index( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
216
216-209-18
inproject
add_data_frame_index
[ "add_data_frame", "add_data_frame_index", "add_df", "add_df_index", "add_dimension", "add_measure", "add_np_array", "add_record", "add_records", "add_series", "add_series_list", "add_spark_df", "build", "clear", "copy", "dump", "filter", "from_json", "fromkeys", "get", "items", "keys", "pop", "popitem", "set_filter", "setdefault", "update", "values", "_add_named_value", "_add_value", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__" ]
# pylint: disable=missing-module-docstring,missing-class-docstring,missing-function-docstring import pandas as pd from tests.test_data import DataWithAssets from tests.utils.import_error import RaiseImportError class TestDf(DataWithAssets): def test_add_df_if_pandas_not_installed(self) -> None: with RaiseImportError.module_name("pandas"): with self.assertRaises(ImportError): self.data.add_df(pd.DataFrame()) def test_add_df_with_none(self) -> None: self.data.add_df(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_empty_df(self) -> None: self.data.add_df(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_df_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_df(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) def test_add_df_with_df_and_with_include_index(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df(df, include_index="Index") self.assertEqual( self.ref_pd_df_by_series_with_index, self.data.build(), ) def test_add_df_with_df_and_max_rows(self) -> None: df = self.in_pd_df_by_series self.data.add_df(df, max_rows=2) self.assertEqual( self.ref_pd_df_by_series_max_rows, self.data.build(), ) class TestDataFrame(DataWithAssets): def test_add_data_frame_with_none(self) -> None: self.data.add_data_frame(None) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_empty_df(self) -> None: self.data.add_data_frame(pd.DataFrame()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_df(self) -> None: df = self.in_pd_df_by_series_with_duplicated_popularity self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_duplicated_popularity, self.data.build(), ) def test_add_data_frame_with_df_contains_na(self) -> None: df = self.in_pd_df_by_series_with_nan self.data.add_data_frame(df) self.assertEqual( self.ref_pd_df_by_series_with_nan, self.data.build(), ) class TestDfWithSeries(DataWithAssets): def test_add_df_with_empty_series(self) -> None: self.data.add_df(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_with_series(self) -> None: self.data.add_df(self.in_pd_series_dimension) self.data.add_df(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_df_with_series_contains_na(self) -> None: self.data.add_df(self.in_pd_series_dimension_with_nan) self.data.add_df(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) def test_add_df_with_series_and_with_include_index(self) -> None: self.data.add_df( self.in_pd_series_dimension_with_index, include_index="DimensionIndex", ) self.data.add_df( self.in_pd_series_measure_with_index, include_index="MeasureIndex", ) self.assertEqual( self.ref_pd_series_with_index, self.data.build(), ) class TestDataFrameWithSeries(DataWithAssets): def test_add_data_frame_with_empty_series(self) -> None: self.data.add_data_frame(pd.Series()) self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_with_series(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension) self.data.add_data_frame(self.in_pd_series_measure) self.assertEqual( self.ref_pd_series, self.data.build(), ) def test_add_data_frame_with_series_contains_na(self) -> None: self.data.add_data_frame(self.in_pd_series_dimension_with_nan) self.data.add_data_frame(self.in_pd_series_measure_with_nan) self.assertEqual( self.ref_pd_series_with_nan, self.data.build(), ) class TestDfIndex(DataWithAssets): def test_add_df_index_with_none(self) -> None: self.data.add_df_index(None, column_name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_df_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_df_index(df, column_name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDataFrameIndex(DataWithAssets): def test_add_data_frame_index_with_none(self) -> None: self.data.add_data_frame_index(None, name="Index") self.assertEqual( {"data": {}}, self.data.build(), ) def test_add_data_frame_index_with_df(self) -> None: df = self.in_pd_df_by_series_with_index self.data.add_data_frame_index(df, name="Index") self.assertEqual( self.ref_pd_df_by_series_only_index, self.data.build(), ) class TestDfIndexWithSeries(DataWithAssets): def test_add_df_index_with_series(self) -> None: self.data.add_df_index( self.in_pd_series_dimension_with_index, column_name="DimensionIndex", ) self.data.add_df_index( self.in_pd_series_measure_with_index, column_name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), ) class TestDataFrameIndexWithSeries(DataWithAssets): def test_add_data_frame_index_with_series(self) -> None: self.data.
( self.in_pd_series_dimension_with_index, name="DimensionIndex", ) self.data.add_data_frame_index( self.in_pd_series_measure_with_index, name="MeasureIndex", ) self.assertEqual( self.ref_pd_series_only_index, self.data.build(), )
vizzuhq__ipyvizzu
222
222-32-13
random
errno
[ "args", "errno", "filename", "filename2", "strerror", "with_traceback", "__annotations__", "__cause__", "__class__", "__context__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__suppress_context__", "__traceback__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.
!= errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-32-28
random
ENOENT
[ "E2BIG", "EACCES", "EADDRINUSE", "EADDRNOTAVAIL", "EADV", "EAFNOSUPPORT", "EAGAIN", "EALREADY", "EBADE", "EBADF", "EBADFD", "EBADMSG", "EBADR", "EBADRQC", "EBADSLT", "EBFONT", "EBUSY", "ECANCELED", "ECHILD", "ECHRNG", "ECOMM", "ECONNABORTED", "ECONNREFUSED", "ECONNRESET", "EDEADLCK", "EDEADLOCK", "EDESTADDRREQ", "EDOM", "EDOTDOT", "EDQUOT", "EEXIST", "EFAULT", "EFBIG", "EHOSTDOWN", "EHOSTUNREACH", "EIDRM", "EILSEQ", "EINPROGRESS", "EINTR", "EINVAL", "EIO", "EISCONN", "EISDIR", "EISNAM", "EKEYEXPIRED", "EKEYREJECTED", "EKEYREVOKED", "EL2HLT", "EL2NSYNC", "EL3HLT", "EL3RST", "ELIBACC", "ELIBBAD", "ELIBEXEC", "ELIBMAX", "ELIBSCN", "ELNRNG", "ELOOP", "EMEDIUMTYPE", "EMFILE", "EMLINK", "EMSGSIZE", "EMULTIHOP", "ENAMETOOLONG", "ENAVAIL", "ENETDOWN", "ENETRESET", "ENETUNREACH", "ENFILE", "ENOANO", "ENOBUFS", "ENOCSI", "ENODATA", "ENODEV", "ENOENT", "ENOEXEC", "ENOKEY", "ENOLCK", "ENOLINK", "ENOMEDIUM", "ENOMEM", "ENOMSG", "ENONET", "ENOPKG", "ENOPROTOOPT", "ENOSPC", "ENOSR", "ENOSTR", "ENOSYS", "ENOTBLK", "ENOTCONN", "ENOTDIR", "ENOTEMPTY", "ENOTNAM", "ENOTRECOVERABLE", "ENOTSOCK", "ENOTSUP", "ENOTTY", "ENOTUNIQ", "ENXIO", "EOPNOTSUPP", "EOVERFLOW", "EOWNERDEAD", "EPERM", "EPFNOSUPPORT", "EPIPE", "EPROTO", "EPROTONOSUPPORT", "EPROTOTYPE", "ERANGE", "EREMCHG", "EREMOTE", "EREMOTEIO", "ERESTART", "ERFKILL", "EROFS", "errorcode", "ESHUTDOWN", "ESOCKTNOSUPPORT", "ESPIPE", "ESRCH", "ESRMNT", "ESTALE", "ESTRPIPE", "ETIME", "ETIMEDOUT", "ETOOMANYREFS", "ETXTBSY", "EUCLEAN", "EUNATCH", "EUSERS", "EWOULDBLOCK", "EXDEV", "EXFULL", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.
: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-55-9
inproject
close
[ "buffer", "close", "closed", "closefd", "detach", "encoding", "errors", "fileno", "flush", "isatty", "line_buffering", "mode", "name", "newlines", "peek", "raw", "read", "read1", "readable", "readall", "readinto", "readinto1", "readline", "readlines", "reconfigure", "seek", "seekable", "tell", "truncate", "writable", "write", "write_through", "writelines", "_blksize", "_checkClosed", "_checkReadable", "_checkSeekable", "_checkWritable", "_CHUNK_SIZE", "_dealloc_warn", "_finalizing", "_is_protocol", "__annotations__", "__class__", "__class_getitem__", "__del__", "__delattr__", "__dict__", "__dir__", "__doc__", "__enter__", "__eq__", "__exit__", "__format__", "__ge__", "__getattribute__", "__gt__", "__hash__", "__init__", "__init_subclass__", "__iter__", "__le__", "__lt__", "__module__", "__ne__", "__new__", "__next__", "__parameters__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__", "__subclasshook__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.
() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-90-10
commited
environ
[ "abc", "abort", "access", "add_dll_directory", "altsep", "chdir", "chflags", "chmod", "chown", "chroot", "CLD_CONTINUED", "CLD_DUMPED", "CLD_EXITED", "CLD_TRAPPED", "close", "closerange", "confstr", "confstr_names", "cpu_count", "ctermid", "curdir", "defpath", "device_encoding", "devnull", "DirEntry", "dup", "dup2", "environ", "environb", "error", "EX_CANTCREAT", "EX_CONFIG", "EX_DATAERR", "EX_IOERR", "EX_NOHOST", "EX_NOINPUT", "EX_NOPERM", "EX_NOTFOUND", "EX_NOUSER", "EX_OK", "EX_OSERR", "EX_OSFILE", "EX_PROTOCOL", "EX_SOFTWARE", "EX_TEMPFAIL", "EX_UNAVAILABLE", "EX_USAGE", "execl", "execle", "execlp", "execlpe", "execv", "execve", "execvp", "execvpe", "extsep", "F_LOCK", "F_OK", "F_TEST", "F_TLOCK", "F_ULOCK", "fchdir", "fchmod", "fchown", "fdatasync", "fdopen", "fork", "forkpty", "fpathconf", "fsdecode", "fsencode", "fspath", "fstat", "fstatvfs", "fsync", "ftruncate", "fwalk", "GenericAlias", "get_blocking", "get_exec_path", "get_inheritable", "get_terminal_size", "getcwd", "getcwdb", "getegid", "getenv", "getenvb", "geteuid", "getgid", "getgrouplist", "getgroups", "getloadavg", "getlogin", "getpgid", "getpgrp", "getpid", "getppid", "getpriority", "getrandom", "getresgid", "getresuid", "getsid", "getuid", "getxattr", "GRND_NONBLOCK", "GRND_RANDOM", "initgroups", "isatty", "kill", "killpg", "lchflags", "lchmod", "lchown", "linesep", "link", "listdir", "listxattr", "lockf", "lseek", "lstat", "major", "makedev", "makedirs", "Mapping", "memfd_create", "MFD_ALLOW_SEALING", "MFD_CLOEXEC", "MFD_HUGE_16GB", "MFD_HUGE_16MB", "MFD_HUGE_1GB", "MFD_HUGE_1MB", "MFD_HUGE_256MB", "MFD_HUGE_2GB", "MFD_HUGE_2MB", "MFD_HUGE_32MB", "MFD_HUGE_512KB", "MFD_HUGE_512MB", "MFD_HUGE_64KB", "MFD_HUGE_8MB", "MFD_HUGE_MASK", "MFD_HUGE_SHIFT", "MFD_HUGETLB", "minor", "mkdir", "mkfifo", "mknod", "MutableMapping", "name", "NGROUPS_MAX", "nice", "O_ACCMODE", "O_APPEND", "O_ASYNC", "O_BINARY", "O_CLOEXEC", "O_CREAT", "O_DIRECT", "O_DIRECTORY", "O_DSYNC", "O_EXCL", "O_EXLOCK", "O_LARGEFILE", "O_NDELAY", "O_NOATIME", "O_NOCTTY", "O_NOFOLLOW", "O_NOINHERIT", "O_NONBLOCK", "O_PATH", "O_RANDOM", "O_RDONLY", "O_RDWR", "O_RSYNC", "O_SEQUENTIAL", "O_SHLOCK", "O_SHORT_LIVED", "O_SYNC", "O_TEMPORARY", "O_TEXT", "O_TMPFILE", "O_TRUNC", "O_WRONLY", "open", "openpty", "P_ALL", "P_DETACH", "P_NOWAIT", "P_NOWAITO", "P_OVERLAY", "P_PGID", "P_PID", "P_WAIT", "pardir", "path", "pathconf", "pathconf_names", "PathLike", "pathsep", "pipe", "pipe2", "plock", "popen", "POSIX_FADV_DONTNEED", "POSIX_FADV_NOREUSE", "POSIX_FADV_NORMAL", "POSIX_FADV_RANDOM", "POSIX_FADV_SEQUENTIAL", "POSIX_FADV_WILLNEED", "posix_fadvise", "posix_fallocate", "pread", "PRIO_PGRP", "PRIO_PROCESS", "PRIO_USER", "putenv", "pwrite", "R_OK", "read", "readlink", "readv", "register_at_fork", "remove", "removedirs", "removexattr", "rename", "renames", "replace", "rmdir", "RTLD_DEEPBIND", "RTLD_GLOBAL", "RTLD_LAZY", "RTLD_LOCAL", "RTLD_NODELETE", "RTLD_NOLOAD", "RTLD_NOW", "scandir", "SCHED_BATCH", "SCHED_FIFO", "sched_get_priority_max", "sched_get_priority_min", "sched_getaffinity", "sched_getparam", "sched_getscheduler", "SCHED_IDLE", "SCHED_OTHER", "sched_param", "SCHED_RESET_ON_FORK", "SCHED_RR", "sched_rr_get_interval", "sched_setaffinity", "sched_setparam", "sched_setscheduler", "SCHED_SPORADIC", "sched_yield", "SEEK_CUR", "SEEK_DATA", "SEEK_END", "SEEK_HOLE", "SEEK_SET", "sendfile", "sep", "set_blocking", "set_inheritable", "setegid", "seteuid", "setgid", "setgroups", "setpgid", "setpgrp", "setpriority", "setregid", "setresgid", "setresuid", "setreuid", "setsid", "setuid", "setxattr", "SF_MNOWAIT", "SF_NODISKIO", "SF_SYNC", "spawnl", "spawnle", "spawnlp", "spawnlpe", "spawnv", "spawnve", "spawnvp", "spawnvpe", "st", "ST_APPEND", "ST_MANDLOCK", "ST_NOATIME", "ST_NODEV", "ST_NODIRATIME", "ST_NOEXEC", "ST_NOSUID", "ST_RDONLY", "ST_RELATIME", "ST_SYNCHRONOUS", "ST_WRITE", "startfile", "stat", "stat_result", "statvfs", "statvfs_result", "strerror", "supports_bytes_environ", "supports_dir_fd", "supports_effective_ids", "supports_fd", "supports_follow_symlinks", "symlink", "sync", "sys", "sysconf", "sysconf_names", "system", "tcgetpgrp", "tcsetpgrp", "terminal_size", "times", "times_result", "TMP_MAX", "truncate", "ttyname", "umask", "uname", "uname_result", "unlink", "unsetenv", "urandom", "utime", "W_OK", "wait", "wait3", "wait4", "waitid", "waitid_result", "waitpid", "walk", "WCONTINUED", "WCOREDUMP", "WEXITED", "WEXITSTATUS", "WIFCONTINUED", "WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG", "WNOWAIT", "write", "writev", "WSTOPPED", "WSTOPSIG", "WTERMSIG", "WUNTRACED", "X_OK", "XATTR_CREATE", "XATTR_REPLACE", "XATTR_SIZE_MAX", "_AddedDllDirectory", "_check_methods", "_Environ", "_execvpe", "_exists", "_exit", "_fspath", "_fwalk", "_get_exports_list", "_spawnvef", "_walk", "_wrap_close", "__all__", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.
.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-90-18
commited
get
[ "clear", "copy", "decodekey", "decodevalue", "encodekey", "encodevalue", "get", "items", "keys", "pop", "popitem", "setdefault", "update", "values", "_data", "__abc_tpflags__", "__annotations__", "__class__", "__class_getitem__", "__contains__", "__delattr__", "__delitem__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__getitem__", "__hash__", "__init__", "__init_subclass__", "__ior__", "__iter__", "__len__", "__module__", "__ne__", "__new__", "__or__", "__reduce__", "__reduce_ex__", "__repr__", "__reversed__", "__ror__", "__setattr__", "__setitem__", "__sizeof__", "__slots__", "__str__", "__subclasshook__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.
("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-116-20
common
platform
[ "get", "label", "name", "platform", "sequence", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.
.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-116-42
common
sequence
[ "get", "label", "name", "platform", "sequence", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.
) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-408-13
inproject
qc_pulse
[ "label", "name", "qc_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.q
duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-409-13
common
ro_pulse
[ "label", "name", "qc_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.r
start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-418-13
inproject
qcm
[ "label", "name", "qcm", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.q
= qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-421-13
inproject
qcm
[ "label", "name", "qcm", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.q
gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-443-13
inproject
base_duration
[ "base_duration", "initial_value", "label", "name", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.b
= qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-463-13
common
qc2_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.q
start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-463-36
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.p
// 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-464-13
common
ro_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.r
start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-464-35
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.p
+ value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-479-13
common
ro_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.r
start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-479-39
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.p
/2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-494-13
common
qc2_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.q
start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-494-36
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.p
/2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-495-13
common
qc3_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.q
start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-495-41
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.p
//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-496-13
common
ro_pulse
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.r
start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-496-39
common
pi_pulse_length
[ "initial_value", "label", "name", "pi_pulse_length", "qc2_pulse", "qc3_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.p
+ 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-505-13
inproject
qrm
[ "label", "name", "qrm", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.q
= qrm def set(self,value): self.qrm.gain = value / 100
qiboteam__qibolab
222
222-508-13
inproject
qrm
[ "label", "name", "qrm", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np import matplotlib.pyplot as plt import yaml # TODO: Have a look in the documentation of ``MeasurementControl`` from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter # TODO: Check why this set_datadir is needed set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") def backup_config_file(): import os import shutil import errno from datetime import datetime original = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) now = datetime.now() now = now.strftime("%d%m%Y%H%M%S") destination_file_name = "tiiq_" + now + ".yml" target = os.path.realpath(os.path.join(os.path.dirname(__file__), 'data/settings_backups', destination_file_name)) try: print("Copying file: " + original) print("Destination file" + target) shutil.copyfile(original, target) print("Platform settings backup done") except IOError as e: # ENOENT(2): file does not exist, raised also on missing dest parent dir if e.errno != errno.ENOENT: raise # try creating parent directories os.makedirs(os.path.dirname(target)) shutil.copy(original, target) def get_config_parameter(dictID, dictID1, key): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path) as file: settings = yaml.safe_load(file) file.close() if (not dictID1): return settings[dictID][key] else: return settings[dictID][dictID1][key] def save_config_parameter(dictID, dictID1, key, value): import os calibration_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..', 'src', 'qibolab', 'runcards', 'tiiq.yml')) with open(calibration_path, "r") as file: settings = yaml.safe_load(file) file.close() if (not dictID1): settings[dictID][key] = value print("Saved value: " + str(settings[dictID][key])) else: settings[dictID][dictID1][key] = value print("Saved value: " + str(settings[dictID][dictID1][key])) with open(calibration_path, "w") as file: settings = yaml.dump(settings, file, sort_keys=False, indent=4) file.close() def plot(smooth_dataset, dataset, label, type): if (type == 0): #cavity plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmax()], smooth_dataset[smooth_dataset.argmax()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return if (type == 1): #qubit spec, rabi, ramsey, t1 plots fig, ax = plt.subplots(1, 1, figsize=(15, 15/2/1.61)) ax.plot(dataset['x0'].values, dataset['y0'].values,'-',color='C0') ax.plot(dataset['x0'].values, smooth_dataset,'-',color='C1') ax.title.set_text(label) ax.plot(dataset['x0'].values[smooth_dataset.argmin()], smooth_dataset[smooth_dataset.argmin()], 'o', color='C2') plt.savefig(pathlib.Path("data") / f"{label}.pdf") return def create_measurement_control(name): import os if os.environ.get("ENABLE_PLOTMON", True): mc = MeasurementControl(f'MC {name}') from quantify_core.visualization.pyqt_plotmon import PlotMonitor_pyqt plotmon = PlotMonitor_pyqt(f'Plot Monitor {name}') plotmon.tuids_max_num(3) mc.instr_plotmon(plotmon.name) from quantify_core.visualization.instrument_monitor import InstrumentMonitor insmon = InstrumentMonitor(f"Instruments Monitor {name}") mc.instrument_monitor(insmon.name) return mc, plotmon, insmon else: mc = MeasurementControl(f'MC {name}') return mc, None, None class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence) def variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step): #[. . . . . .][...................]0[...................][. . . . . .] #[-------- lowres_width ---------][-- highres_width --] [-- highres_width --][-------- lowres_width ---------] #>. .< lowres_step # >..< highres_step # ^ centre value = 0 scanrange = np.concatenate( ( np.arange(-lowres_width,-highres_width,lowres_step), np.arange(-highres_width,highres_width,highres_step), np.arange(highres_width,lowres_width,lowres_step) ) ) return scanrange def run_resonator_spectroscopy(platform, mc, sequence, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): #Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:25]) * 1e6 # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_punchout(platform, mc, sequence, ro_pulse, precision_width, precision_step): platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) scanrange = scanrange + platform.LO_qrm.get_frequency() mc.settables([Settable(platform.LO_qrm.device.frequency), Settable(QRPulseGainParameter(platform.qrm))]) setpoints_gain = np.arange(10, 100, 10) mc.setpoints_grid([scanrange, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Punchout", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) #FIXME: Code Lorentzian fitting for cavity spec and punchout resonator_freq = dataset['x0'].values[dataset['y0'].argmax().values]+ro_pulse.frequency print(f"\nResonator Frequency = {resonator_freq}") print(f"\nResonator LO Frequency = {resonator_freq - ro_pulse.frequency}") return resonator_freq, smooth_dataset, dataset def run_qubit_spectroscopy(platform, mc, resonator_freq, sequence, qc_pulse, ro_pulse, fast_start, fast_end, fast_step, precision_start, precision_end, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.software_averages = 1 # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=platform.software_averages) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq - qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(1, 400, 1)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = platform.software_averages) platform.stop() return dataset, platform.qcm.gain def run_rabi_pulse_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): #qubit pulse duration=200 platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 3 mc.settables(Settable(QCPulseGainParameter(platform.qcm))) mc.setpoints(np.arange(0, 100, 10)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Gain', soft_avg = platform.software_averages) platform.stop() return dataset def run_rabi_pulse_length_and_gain(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseGainParameter(platform.qcm))]) setpoints_length = np.arange(1, 400, 10) setpoints_gain = np.arange(0, 20, 1) mc.setpoints_grid([setpoints_length, setpoints_gain]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_rabi_pulse_length_and_amplitude(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.software_averages = 1 mc.settables([Settable(QCPulseLengthParameter(ro_pulse, qc_pulse)), Settable(QCPulseAmplitudeParameter(qc_pulse))]) setpoints_length = np.arange(1, 1000, 2) setpoints_amplitude = np.arange(0, 100, 2) mc.setpoints_grid([setpoints_length, setpoints_amplitude]) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length and Gain', soft_avg = platform.software_averages) # Analyse data to look for the smallest qc_pulse length that renders off-resonance amplitude, determine corresponding pi_pulse gain # platform.pi_pulse_length = # platform.pi_pulse_gain = platform.stop() return dataset def run_t1(platform, mc,resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, delay_before_readout_start, delay_before_readout_end, delay_before_readout_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = platform.software_averages) platform.stop() return dataset def run_ramsey(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_duration, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(RamseyWaitParameter(ro_pulse, qc2_pulse, pi_pulse_duration))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Ramsey', soft_avg = platform.software_averages) platform.stop() return dataset def run_spin_echo(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(Settable(SpinEchoWaitParameter(ro_pulse, qc2_pulse, pi_pulse_length))) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo', soft_avg = platform.software_averages) platform.stop() return dataset # Spin Echo 3 Pulses: RX(pi/2) - wait t(rotates z) - RX(pi) - wait t(rotates z) - RX(pi/2) - readout def run_spin_echo_3pulses(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, qc2_pulse, qc3_pulse, ro_pulse, pi_pulse_gain, pi_pulse_length, pi_pulse_amplitude, start_start, start_end, start_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) platform.qcm.gain = pi_pulse_gain mc.settables(SpinEcho3PWaitParameter(ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length)) mc.setpoints(np.arange(start_start, start_end, start_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Spin Echo 3 Pulses', soft_avg = platform.software_averages) platform.stop() return dataset def run_shifted_resonator_spectroscopy(platform, mc, resonator_freq, qubit_freq, sequence, qc_pulse, ro_pulse, lowres_width, lowres_step, highres_width, highres_step, precision_width, precision_step): platform.LO_qrm.set_frequency(resonator_freq - ro_pulse.frequency) platform.LO_qcm.set_frequency(qubit_freq + qc_pulse.frequency) # Fast Sweep platform.software_averages = 1 scanrange = variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Fast", soft_avg=platform.software_averages) platform.stop() shifted_LO_frequency = dataset['x0'].values[dataset['y0'].argmax().values] # Precision Sweep platform.software_averages = 1 scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + shifted_LO_frequency) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Resonator Spectroscopy Shifted Precision", soft_avg=platform.software_averages) platform.stop() smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) shifted_frequency = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency shifted_max_ro_voltage = smooth_dataset.max() * 1e6 print('\n') print(f"\nResonator Frequency = {shifted_frequency}") print(f"Maximum Voltage Measured = {shifted_max_ro_voltage} μV") return shifted_frequency, shifted_max_ro_voltage, smooth_dataset, dataset # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class QCPulseGainParameter(): label = 'Qubit Control Gain' unit = '%' name = 'qc_pulse_gain' def __init__(self, qcm): self.qcm = qcm def set(self,value): self.qcm.gain = value / 100 class QCPulseAmplitudeParameter(): label = 'Qubit Control Pulse Amplitude' unit = '%' name = 'qc_pulse_amplitude' def __init__(self, qc_pulse): self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.amplitude = value / 100 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class RamseyWaitParameter(): label = 'Time' unit = 'ns' name = 'ramsey_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length // 2 + value self.ro_pulse.start = self.pi_pulse_length + value + 4 class SpinEchoWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.pi_pulse_length = pi_pulse_length def set(self, value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.ro_pulse.start = 3 * self.pi_pulse_length//2 + 2 * value + 4 class SpinEcho3PWaitParameter(): label = 'Time' unit = 'ns' name = 'spin_echo_wait' initial_value = 0 def __init__(self, ro_pulse, qc2_pulse, qc3_pulse, pi_pulse_length): self.ro_pulse = ro_pulse self.qc2_pulse = qc2_pulse self.qc3_pulse = qc3_pulse self.pi_pulse_length = pi_pulse_length def set(self,value): self.qc2_pulse.start = self.pi_pulse_length//2 + value self.qc3_pulse.start = (3 * self.pi_pulse_length)//2 + 2 * value self.ro_pulse.start = 2 * self.pi_pulse_length + 2 * value + 4 class QRPulseGainParameter(): label = 'Qubit Readout Gain' unit = '%' name = 'ro_pulse_gain' def __init__(self, qrm): self.qrm = qrm def set(self,value): self.q
gain = value / 100
qiboteam__qibolab
223
223-26-13
inproject
mc
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.
, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-26-22
inproject
pl
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.
, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-26-31
inproject
ins
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.
= utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-26-43
inproject
create_measurement_control
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.
('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-46-17
inproject
add
[ "add", "add_measurement", "add_u3", "phase", "pulses", "qcm_pulses", "qrm_pulses", "time", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.
(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-61-26
inproject
variable_resolution_scanrange
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.
(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-87-28
inproject
lorentzian_fit
[ "BaseAnalysis", "curve_fit", "data_post", "exp", "lmfit", "lorentzian_fit", "np", "os", "pathlib", "plt", "rabi", "rabi_fit", "ramsey", "ramsey_fit", "resonator_peak", "set_datadir", "t1_fit", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.
("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-96-18
random
mc
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.
ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-145-14
inproject
plot
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.
(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-147-28
inproject
lorentzian_fit
[ "BaseAnalysis", "curve_fit", "data_post", "exp", "lmfit", "lorentzian_fit", "np", "os", "pathlib", "plt", "rabi", "rabi_fit", "ramsey", "ramsey_fit", "resonator_peak", "set_datadir", "t1_fit", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.
("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-168-18
infile
load_settings
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.
() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-186-96
inproject
rabi_fit
[ "BaseAnalysis", "curve_fit", "data_post", "exp", "lmfit", "lorentzian_fit", "np", "os", "pathlib", "plt", "rabi", "rabi_fit", "ramsey", "ramsey_fit", "resonator_peak", "set_datadir", "t1_fit", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.
(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-188-14
inproject
plot
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.
(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-217-17
inproject
add
[ "add", "add_measurement", "add_u3", "phase", "pulses", "qcm_pulses", "qrm_pulses", "time", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.
(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-239-37
inproject
t1_fit
[ "BaseAnalysis", "curve_fit", "data_post", "exp", "lmfit", "lorentzian_fit", "np", "os", "pathlib", "plt", "rabi", "rabi_fit", "ramsey", "ramsey_fit", "resonator_peak", "set_datadir", "t1_fit", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.
(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-240-14
inproject
plot
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.
(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-267-21
inproject
add
[ "add", "add_measurement", "add_u3", "phase", "pulses", "qcm_pulses", "qrm_pulses", "time", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.
(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-272-21
inproject
add
[ "add", "add_measurement", "add_u3", "phase", "pulses", "qcm_pulses", "qrm_pulses", "time", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.
(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-304-14
inproject
backup_config_file
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.
(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-307-88
infile
run_resonator_spectroscopy
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.
() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-319-67
infile
run_qubit_spectroscopy
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.
() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-328-121
inproject
run_rabi_pulse_length
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.
() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-330-20
non_informative
get_config_parameter
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.
("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-339-80
infile
callibrate_qubit_states
[ "auto_calibrate_plaform", "callibrate_qubit_states", "ins", "load_settings", "mc", "pl", "platform", "run_qubit_spectroscopy", "run_rabi_pulse_length", "run_resonator_spectroscopy", "run_t1", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.
() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-347-14
inproject
plot_qubit_states
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.
(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-353-46
inproject
classify
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.
(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-357-46
inproject
classify
[ "backup_config_file", "classify", "create_measurement_control", "get_config_parameter", "MeasurementControl", "np", "pathlib", "plot", "plot_qubit_states", "plt", "save_config_parameter", "variable_resolution_scanrange", "yaml", "__doc__", "__file__", "__name__", "__package__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.
(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-375-13
common
ro_pulse
[ "label", "name", "qc_pulse", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.
.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-375-22
common
start
[ "amplitude", "channel", "compile", "duration", "frequency", "offset_i", "offset_q", "phase", "qubit", "serial", "shape", "start", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.
= value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-385-13
inproject
base_duration
[ "base_duration", "initial_value", "label", "name", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.
= qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-385-38
inproject
duration
[ "amplitude", "channel", "compile", "duration", "frequency", "offset_i", "offset_q", "phase", "qubit", "serial", "shape", "start", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.
def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-391-13
common
ro_pulse
[ "base_duration", "initial_value", "label", "name", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.
.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-391-22
common
start
[ "amplitude", "channel", "compile", "duration", "frequency", "offset_i", "offset_q", "phase", "qubit", "serial", "shape", "start", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.
= self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-391-35
common
base_duration
[ "base_duration", "initial_value", "label", "name", "ro_pulse", "set", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.
+ 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.sequence)
qiboteam__qibolab
223
223-404-20
common
platform
[ "get", "label", "name", "platform", "sequence", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.
.execute(self.sequence)
qiboteam__qibolab
223
223-404-29
common
execute
[ "connect", "data_folder", "delay_before_readout", "delay_between_pulses", "disconnect", "execute", "fetch_instrument", "fetch_qubit", "fetch_qubit_pi_pulse", "fetch_qubit_readout_pulse", "hardware_avg", "is_connected", "last_qcm_pulses", "last_qrm_pulses", "LO_qcm", "LO_qrm", "max_readout_voltage", "min_readout_voltage", "name", "pi_pulse_amplitude", "pi_pulse_duration", "pi_pulse_frequency", "pi_pulse_gain", "qcm", "qrm", "qubit_frequency", "qubits", "readout_pulse", "reload_settings", "repetition_duration", "resonator_frequency", "run_calibration", "runcard", "sampling_rate", "settings", "setup", "software_averages", "start", "start_experiment", "stop", "_adc", "_check_connected", "_instruments", "_last_sequence", "_lo", "_LO_qcm", "_LO_qrm", "_qcm", "_qrm", "_settings", "__annotations__", "__call__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.
(self.sequence)
qiboteam__qibolab
223
223-404-42
common
sequence
[ "get", "label", "name", "platform", "sequence", "unit", "__annotations__", "__class__", "__delattr__", "__dict__", "__dir__", "__doc__", "__eq__", "__format__", "__getattribute__", "__hash__", "__init__", "__init_subclass__", "__module__", "__ne__", "__new__", "__reduce__", "__reduce_ex__", "__repr__", "__setattr__", "__sizeof__", "__slots__", "__str__" ]
import pathlib import numpy as np #import matplotlib.pyplot as plt import utils import yaml import fitting from qibolab import Platform # TODO: Have a look in the documentation of ``MeasurementControl`` #from quantify_core.measurement import MeasurementControl from quantify_core.measurement.control import Gettable, Settable from quantify_core.data.handling import set_datadir from scipy.signal import savgol_filter from qibolab.pulses import Pulse, ReadoutPulse from qibolab.circuit import PulseSequence from qibolab.pulse_shapes import Rectangular, Gaussian # TODO: Check why this set_datadir is needed #set_datadir(pathlib.Path("data") / "quantify") set_datadir(pathlib.Path(__file__).parent / "data" / "quantify") class Calibration(): def __init__(self, platform: Platform): self.platform = platform self.mc, self.pl, self.ins = utils.create_measurement_control('Calibration') def load_settings(self): # Load diagnostics settings with open("calibration.yml", "r") as file: return yaml.safe_load(file) def run_resonator_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['resonator_spectroscopy'] lowres_width = ds['lowres_width'] lowres_step = ds['lowres_step'] highres_width = ds['highres_width'] highres_step = ds['highres_step'] precision_width = ds['precision_width'] precision_step = ds['precision_step'] #Fast Sweep scanrange = utils.variable_resolution_scanrange(lowres_width, lowres_step, highres_width, highres_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Fast", soft_avg=1) platform.stop() platform.LO_qrm.set_frequency(dataset['x0'].values[dataset['y0'].argmax().values]) avg_min_voltage = np.mean(dataset['y0'].values[:(lowres_width//lowres_step)]) * 1e6 # Precision Sweep scanrange = np.arange(-precision_width, precision_width, precision_step) mc.settables(platform.LO_qrm.device.frequency) mc.setpoints(scanrange + platform.LO_qrm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() platform.LO_qcm.off() dataset = mc.run("Resonator Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 25, 2) # resonator_freq = dataset['x0'].values[smooth_dataset.argmax()] + ro_pulse.frequency max_ro_voltage = smooth_dataset.max() * 1e6 f0, BW, Q = fitting.lorentzian_fit("last", max, "Resonator_spectroscopy") resonator_freq = (f0*1e9 + ro_pulse.frequency) print(f"\nResonator Frequency = {resonator_freq}") return resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset def run_qubit_spectroscopy(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['qubit_spectroscopy'] fast_start = ds['fast_start'] fast_end = ds['fast_end'] fast_step = ds['fast_step'] precision_start = ds['precision_start'] precision_end = ds['precision_end'] precision_step = ds['precision_step'] # Fast Sweep fast_sweep_scan_range = np.arange(fast_start, fast_end, fast_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(fast_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Fast", soft_avg=1) platform.stop() # Precision Sweep platform.software_averages = 1 precision_sweep_scan_range = np.arange(precision_start, precision_end, precision_step) mc.settables(platform.LO_qcm.device.frequency) mc.setpoints(precision_sweep_scan_range + platform.LO_qcm.get_frequency()) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run("Qubit Spectroscopy Precision", soft_avg=software_averages) platform.stop() # Fitting smooth_dataset = savgol_filter(dataset['y0'].values, 11, 2) qubit_freq = dataset['x0'].values[smooth_dataset.argmin()] - qc_pulse.frequency min_ro_voltage = smooth_dataset.min() * 1e6 print(f"\nQubit Frequency = {qubit_freq}") utils.plot(smooth_dataset, dataset, "Qubit_Spectroscopy", 1) print("Qubit freq ontained from MC results: ", qubit_freq) f0, BW, Q = fitting.lorentzian_fit("last", min, "Qubit_Spectroscopy") qubit_freq = (f0*1e9 - qc_pulse.frequency) print("Qubit freq ontained from fitting: ", qubit_freq) return qubit_freq, min_ro_voltage, smooth_dataset, dataset def run_rabi_pulse_length(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] qc_pulse_shape = eval(ps['qc_spectroscopy_pulse'].popitem()[1]) qc_pulse_settings = ps['qc_spectroscopy_pulse'] qc_pulse = Pulse(**qc_pulse_settings, shape = qc_pulse_shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['rabi_pulse_length'] pulse_duration_start = ds['pulse_duration_start'] pulse_duration_end = ds['pulse_duration_end'] pulse_duration_step = ds['pulse_duration_step'] mc.settables(Settable(QCPulseLengthParameter(ro_pulse, qc_pulse))) mc.setpoints(np.arange(pulse_duration_start, pulse_duration_end, pulse_duration_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('Rabi Pulse Length', soft_avg = software_averages) platform.stop() # Fitting pi_pulse_amplitude = qc_pulse.amplitude smooth_dataset, pi_pulse_duration, rabi_oscillations_pi_pulse_min_voltage, t1 = fitting.rabi_fit(dataset) pi_pulse_gain = platform.qcm.gain utils.plot(smooth_dataset, dataset, "Rabi_pulse_length", 1) print(f"\nPi pulse duration = {pi_pulse_duration}") print(f"\nPi pulse amplitude = {pi_pulse_amplitude}") #Check if the returned value from fitting is correct. print(f"\nPi pulse gain = {pi_pulse_gain}") #Needed? It is equal to the QCM gain when performing a Rabi. print(f"\nrabi oscillation min voltage = {rabi_oscillations_pi_pulse_min_voltage}") print(f"\nT1 = {t1}") return dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 # T1: RX(pi) - wait t(rotates z) - readout def run_t1(self): platform = self.platform platform.reload_settings() mc = self.mc ps = platform.settings['settings'] start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) sequence = PulseSequence() sequence.add(qc_pi_pulse) sequence.add(ro_pulse) ds = self.load_settings() self.pl.tuids_max_num(ds['max_num_plots']) software_averages = ds['software_averages'] ds = ds['t1'] delay_before_readout_start = ds['delay_before_readout_start'] delay_before_readout_end = ds['delay_before_readout_end'] delay_before_readout_step = ds['delay_before_readout_step'] mc.settables(Settable(T1WaitParameter(ro_pulse, qc_pi_pulse))) mc.setpoints(np.arange(delay_before_readout_start, delay_before_readout_end, delay_before_readout_step)) mc.gettables(Gettable(ROController(platform, sequence))) platform.start() dataset = mc.run('T1', soft_avg = software_averages) platform.stop() # Fitting smooth_dataset, t1 = fitting.t1_fit(dataset) utils.plot(smooth_dataset, dataset, "t1", 1) print(f'\nT1 = {t1}') return t1, smooth_dataset, dataset def callibrate_qubit_states(self): platform = self.platform platform.reload_settings() ps = platform.settings['settings'] niter=10 nshots=1 #create exc and gnd pulses start = 0 frequency = ps['pi_pulse_frequency'] amplitude = ps['pi_pulse_amplitude'] duration = ps['pi_pulse_duration'] phase = 0 shape = eval(ps['pi_pulse_shape']) qc_pi_pulse = Pulse(start, duration, amplitude, frequency, phase, shape) ro_pulse_shape = eval(ps['readout_pulse'].popitem()[1]) ro_pulse_settings = ps['readout_pulse'] ro_pulse = ReadoutPulse(**ro_pulse_settings, shape = ro_pulse_shape) exc_sequence = PulseSequence() exc_sequence.add(qc_pi_pulse) gnd_sequence.add(ro_pulse) gnd_sequence = PulseSequence() #ro_pulse.start=0 gnd_sequence.add(ro_pulse) platform.LO_qrm.set_frequency(ps['resonator_freq'] - ro_pulse.frequency) platform.LO_qcm.set_frequency(ps['qubit_freq'] + qc_pi_pulse.frequency) platform.start() #Exectue niter single gnd shots platform.LO_qcm.off() all_gnd_states = [] for i in range(niter): qubit_state = platform.execute(gnd_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_gnd_states.add(point) #Exectue niter single exc shots platform.LO_qcm.on() all_exc_states = [] for i in range(niter): qubit_state = platform.execute(exc_sequence, nshots) #Compose complex point from i, q obtained from execution point = complex(qubit_state[2], qubit_state[3]) all_exc_states.add(point) platform.stop() return all_gnd_states, np.mean(all_gnd_states), all_exc_states, np.mean(all_exc_states) def auto_calibrate_plaform(self): platform = self.platform #backup latest platform runcard utils.backup_config_file(platform) #run and save cavity spectroscopy calibration resonator_freq, avg_min_voltage, max_ro_voltage, smooth_dataset, dataset = self.run_resonator_spectroscopy() print(utils.get_config_parameter("settings", "", "resonator_freq")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage")) print(utils.get_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage")) print(utils.get_config_parameter("LO_QRM_settings", "", "frequency")) # utils.save_config_parameter("settings", "", "resonator_freq", float(resonator_freq)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_avg_min_ro_voltage", float(avg_min_voltage)) # utils.save_config_parameter("settings", "", "resonator_spectroscopy_max_ro_voltage", float(max_ro_voltage)) # utils.save_config_parameter("LO_QRM_settings", "", "frequency", float(resonator_freq - 20_000_000)) #run and save qubit spectroscopy calibration qubit_freq, min_ro_voltage, smooth_dataset, dataset = self.run_qubit_spectroscopy() print(utils.get_config_parameter("settings", "", "qubit_freq")) print(utils.get_config_parameter("LO_QCM_settings", "", "frequency")) print(utils.get_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage")) # utils.save_config_parameter("settings", "", "qubit_freq", float(qubit_freq)) # utils.save_config_parameter("LO_QCM_settings", "", "frequency", float(qubit_freq + 200_000_000)) # utils.save_config_parameter("settings", "", "qubit_spectroscopy_min_ro_voltage", float(min_ro_voltage)) # #run Rabi and save Pi pulse params from calibration dataset, pi_pulse_duration, pi_pulse_amplitude, pi_pulse_gain, rabi_oscillations_pi_pulse_min_voltage, t1 = self.run_rabi_pulse_length() print(utils.get_config_parameter("settings", "", "pi_pulse_duration")) print(utils.get_config_parameter("settings", "", "pi_pulse_amplitude")) print(utils.get_config_parameter("settings", "", "pi_pulse_gain")) print(utils.get_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage")) # utils.save_config_parameter("settings", "", "pi_pulse_duration", int(pi_pulse_duration)) # utils.save_config_parameter("settings", "", "pi_pulse_amplitude", float(pi_pulse_amplitude)) # utils.save_config_parameter("settings", "", "pi_pulse_gain", float(pi_pulse_gain)) # utils.save_config_parameter("settings", "", "rabi_oscillations_pi_pulse_min_voltage", float(rabi_oscillations_pi_pulse_min_voltage)) # #run calibration_qubit_states all_gnd_states, mean_gnd_states, all_exc_states, mean_exc_states = self.callibrate_qubit_states() # #TODO: save in runcard mean_gnd_states and mean_exc_states print(all_gnd_states) print(mean_gnd_states) print(all_exc_states) print(mean_exc_states) # #TODO: Remove plot qubit states results when tested utils.plot_qubit_states(all_gnd_states, all_exc_states) #TODO: Remove 0 and 1 classification from auto calibration when tested #Classify all points into 0 and 1 classified_gnd_results = [] for point in all_gnd_states: classified_gnd_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) classified_exc_results = [] for point in all_exc_states: classified_exc_results.add(utils.classify(point, mean_gnd_states, mean_exc_states)) print(classified_gnd_results) print(classified_exc_results) # help classes class QCPulseLengthParameter(): label = 'Qubit Control Pulse Length' unit = 'ns' name = 'qc_pulse_length' def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.qc_pulse = qc_pulse def set(self, value): self.qc_pulse.duration = value self.ro_pulse.start = value + 4 class T1WaitParameter(): label = 'Time' unit = 'ns' name = 't1_wait' initial_value = 0 def __init__(self, ro_pulse, qc_pulse): self.ro_pulse = ro_pulse self.base_duration = qc_pulse.duration def set(self, value): # TODO: implement following condition #must be >= 4ns <= 65535 #platform.delay_before_readout = value self.ro_pulse.start = self.base_duration + 4 + value class ROController(): # Quantify Gettable Interface Implementation label = ['Amplitude', 'Phase','I','Q'] unit = ['V', 'Radians','V','V'] name = ['A', 'Phi','I','Q'] def __init__(self, platform, sequence): self.platform = platform self.sequence = sequence def get(self): return self.platform.execute(self.
)
qiboteam__qibolab