From a10dcaa7f082b57799f63bc2ce1f76488fe5e5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= Date: Tue, 8 Oct 2019 15:04:30 -0400 Subject: [PATCH 1/2] CNOT implem. as edge property --- QGL/ChannelLibraries.py | 4 ++-- QGL/PulsePrimitives.py | 8 +++++++- QGL/config.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/QGL/ChannelLibraries.py b/QGL/ChannelLibraries.py index e350f7b0..adf429a6 100644 --- a/QGL/ChannelLibraries.py +++ b/QGL/ChannelLibraries.py @@ -542,13 +542,13 @@ def set_control(self, qubit_or_edge, transmitter, generator=None): qubit_or_edge.phys_chan.generator = generator self.update_channelDict() - def new_edge(self, source, target): + def new_edge(self, source, target, cnot_impl=config.cnot_implementation): label = f"{source.label}->{target.label}" if label in self.channelDict: edge = self.channelDict[f"{source.label}->{target.label}"] logger.warning(f"The edge {source.label}->{target.label} already exists: using this edge.") else: - edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, channel_db=self.channelDatabase) + edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, cnot_impl = cnot_impl, channel_db=self.channelDatabase) self.add_and_update_dict(edge) return edge diff --git a/QGL/PulsePrimitives.py b/QGL/PulsePrimitives.py index bfbf03b2..5844923d 100644 --- a/QGL/PulsePrimitives.py +++ b/QGL/PulsePrimitives.py @@ -736,7 +736,13 @@ def CNOT_simple(source, target, **kwargs): @_memoize def CNOT(source, target, **kwargs): - cnot_impl = globals()[config.cnot_implementation] + channel = ChannelLibraries.EdgeFactory(source, target) + if hasattr(channel, 'cnot_impl'): + cnot_impl_name = channel.cnot_impl + #print(f'Chosen CNOT implementation: {cnot_impl_name}') + else: + cnot_impl_name = config.cnot_implementation + cnot_impl = globals()[cnot_impl_name] return cnot_impl(source, target, **kwargs) # The worker method for MEAS and MEASA diff --git a/QGL/config.py b/QGL/config.py index e8ae133d..d7050850 100644 --- a/QGL/config.py +++ b/QGL/config.py @@ -31,7 +31,7 @@ # select a CNOT implementation (a name of a Pulse function that implements # CNOT in your gate set, e.g. CNOT_simple or CNOT_CR) -cnot_implementation = "CNOT_simple" +cnot_implementation = "CNOT_CR" def load_config(): global config_file From 4397351d4e81b893ab663b2e269a716693b35c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rist=C3=A8?= Date: Wed, 16 Oct 2019 15:35:28 -0400 Subject: [PATCH 2/2] Don't define cnot_impl at edge creation --- QGL/ChannelLibraries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QGL/ChannelLibraries.py b/QGL/ChannelLibraries.py index 48a25d7a..c26c1261 100644 --- a/QGL/ChannelLibraries.py +++ b/QGL/ChannelLibraries.py @@ -562,7 +562,7 @@ def new_edge(self, source, target): edge = self.channelDict[f"{source.label}->{target.label}"] logger.warning(f"The edge {source.label}->{target.label} already exists: using this edge.") else: - edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, cnot_impl = cnot_impl, channel_db=self.channelDatabase) + edge = Channels.Edge(label=f"{source.label}->{target.label}", source=source, target=target, channel_db=self.channelDatabase) self.add_and_update_dict(edge) return edge