Skip to content

Commit 0fe3fbf

Browse files
authored
Deprecated add_data_qubit to add_qubit [unitaryhack] (#138)
* change * final-change * deprecate-warning * some-html-changes * Updating-suggested-changes
1 parent 16c7dad commit 0fe3fbf

5 files changed

Lines changed: 43 additions & 18 deletions

File tree

docs/components/host.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ <h1>Host<a class="headerlink" href="#host" title="Permalink to this headline">¶
468468
</dd></dl>
469469

470470
<dl class="method">
471-
<dt id="qunetsim.components.host.Host.add_data_qubit">
472-
<code class="sig-name descname">add_data_qubit</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">qubit</em>, <em class="sig-param">q_id=None</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.add_data_qubit" title="Permalink to this definition"></a></dt>
471+
<dt id="qunetsim.components.host.Host.add_qubit">
472+
<code class="sig-name descname">add_data_qubit</code><span class="sig-paren">(</span><em class="sig-param">host_id</em>, <em class="sig-param">qubit</em>, <em class="sig-param">q_id=None</em><span class="sig-paren">)</span><a class="headerlink" href="#qunetsim.components.host.Host.add_qubit" title="Permalink to this definition"></a></dt>
473473
<dd><p>Adds the data qubit to the data qubit store of a host. If the qubit has an ID, adds the qubit with it,
474474
otherwise generates an ID for the qubit and adds the qubit with that ID.</p>
475475
<dl class="field-list simple">
@@ -1616,4 +1616,4 @@ <h1>Host<a class="headerlink" href="#host" title="Permalink to this headline">¶
16161616

16171617

16181618
</body>
1619-
</html>
1619+
</html>

docs/genindex.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ <h2 id="A">A</h2>
357357
</li>
358358
<li><a href="components/host.html#qunetsim.components.host.Host.add_connections">add_connections() (qunetsim.components.host.Host method)</a>
359359
</li>
360-
<li><a href="components/host.html#qunetsim.components.host.Host.add_data_qubit">add_data_qubit() (qunetsim.components.host.Host method)</a>
360+
<li><a href="components/host.html#qunetsim.components.host.Host.add_qubit">add_qubit() (qunetsim.components.host.Host method)</a>
361361
</li>
362362
<li><a href="components/host.html#qunetsim.components.host.Host.add_epr">add_epr() (qunetsim.components.host.Host method)</a>
363363
</li>
@@ -941,4 +941,4 @@ <h2 id="Z">Z</h2>
941941

942942

943943
</body>
944-
</html>
944+
</html>

integration_tests/test_host.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ def test_get_qubits_by_id(self):
2727
q4 = Qubit(host2)
2828

2929
host.add_epr('B', q1)
30-
host.add_data_qubit('C', q2)
30+
host.add_qubit('C', q2)
3131
host.add_ghz_qubit('D', q3)
3232

33-
host2.add_data_qubit('A', q4)
33+
host2.add_qubit('A', q4)
3434

3535
# Test all types of qubits
3636
self.assertEqual(q1, host.get_qubit_by_id(q1.id))
@@ -48,7 +48,7 @@ def test_get_data_qubit(self):
4848
host = Host('A')
4949
q1 = Qubit(host)
5050

51-
host.add_data_qubit('A', q1)
51+
host.add_qubit('A', q1)
5252

5353
qs = host.get_data_qubit('A')
5454
self.assertIsInstance(qs, Qubit)
@@ -57,7 +57,7 @@ def test_get_qubit(self):
5757
host = Host('A')
5858
q1 = Qubit(host)
5959

60-
host.add_data_qubit('A', q1)
60+
host.add_qubit('A', q1)
6161

6262
qs = host.get_qubit('A')
6363
self.assertIsInstance(qs, Qubit)
@@ -69,13 +69,13 @@ def test_get_data_qubits(self):
6969
q2 = Qubit(host)
7070
q3 = Qubit(host)
7171

72-
host.add_data_qubit('B', q1)
72+
host.add_qubit('B', q1)
7373

7474
qs = host.get_data_qubits('B')
7575
self.assertEqual(len(qs), 1)
7676

77-
host.add_data_qubit('B', q2)
78-
host.add_data_qubit('B', q3)
77+
host.add_qubit('B', q2)
78+
host.add_qubit('B', q3)
7979

8080
qs = host.get_data_qubits('B')
8181
self.assertEqual(len(qs), 3)
@@ -92,13 +92,13 @@ def test_get_qubits(self):
9292
q2 = Qubit(host)
9393
q3 = Qubit(host)
9494

95-
host.add_data_qubit('B', q1)
95+
host.add_qubit('B', q1)
9696

9797
qs = host.get_qubits('B')
9898
self.assertEqual(len(qs), 1)
9999

100-
host.add_data_qubit('B', q2)
101-
host.add_data_qubit('B', q3)
100+
host.add_qubit('B', q2)
101+
host.add_qubit('B', q3)
102102

103103
qs = host.get_qubits('B')
104104
self.assertEqual(len(qs), 3)
@@ -116,7 +116,7 @@ def test_resetting_qubits(self):
116116
q3 = Qubit(host)
117117

118118
host.add_epr('B', q1)
119-
host.add_data_qubit('B', q2)
119+
host.add_qubit('B', q2)
120120
host.add_ghz_qubit('B', q3)
121121

122122
qs = host.get_qubits('B')

qunetsim/components/host.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,31 @@ def add_data_qubit(self, host_id, qubit, q_id=None):
13411341
Returns:
13421342
(str): The qubit ID
13431343
"""
1344+
warnings.warn(
1345+
"The 'add_data_qubit' function has been renamed to"
1346+
" 'add_qubit'. The 'add_data_qubit' function will be removed in QuNetStim 1.0.",
1347+
DeprecationWarning,
1348+
stacklevel=3,
1349+
)
1350+
if q_id is not None:
1351+
qubit.id = q_id
1352+
1353+
self._qubit_storage.add_qubit_from_host(qubit, Qubit.DATA_QUBIT, host_id)
1354+
return qubit.id
1355+
1356+
def add_qubit(self, host_id, qubit, q_id=None):
1357+
"""
1358+
Adds the data qubit to the data qubit store of a host. If the qubit has an ID, adds the qubit with it,
1359+
otherwise generates an ID for the qubit and adds the qubit with that ID.
1360+
1361+
Args:
1362+
host_id (str): The ID of the host to pair the qubit
1363+
qubit (Qubit): The data Qubit to be added.
1364+
q_id (str): the ID to set the qubit ID to
1365+
Returns:
1366+
(str): The qubit ID
1367+
"""
1368+
)
13441369
if q_id is not None:
13451370
qubit.id = q_id
13461371

qunetsim/components/protocols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _rec_qubit(packet):
173173
receiver = packet.receiver
174174
qubit = packet.payload
175175
receiver = network.get_host(receiver)
176-
receiver.add_data_qubit(from_host, qubit)
176+
receiver.add_qubit(from_host, qubit)
177177

178178
Logger.get_instance().log(
179179
packet.receiver + ' received qubit ' + packet.payload.id + ' from ' + packet.sender)
@@ -276,7 +276,7 @@ def _rec_teleport(packet):
276276
host_receiver.add_epr(epr_host, q)
277277

278278
elif payload['type'] == Constants.DATA:
279-
host_receiver.add_data_qubit(epr_host, q, q_id=q_id)
279+
host_receiver.add_qubit(epr_host, q, q_id=q_id)
280280

281281
# Always send ACK!
282282
if 'o_seq_num' in payload and 'ack' in payload:

0 commit comments

Comments
 (0)