-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simulator tools -> better create connections (#183)
* simulator tools -> better create connections * changes according to PR * simulator-tools - fixed tests, added readme, moved package * Fixes from PR
- Loading branch information
Showing
9 changed files
with
151 additions
and
652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__all__ = [ | ||
"simulator_tools", | ||
"simulator", | ||
"bakery", | ||
"config", | ||
"control_panel", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Simulator tools | ||
This library includes tools to help simulate programs | ||
|
||
## create_simulator_controller_connections | ||
Creates a list of :class:`~qm.simulate.interface.ControllerConnection` objects with the Inter-controllers connections between controllers in a way which maximizes the optical links connectivity. | ||
For use inside the :class:`~qm.simulate.interface.SimulationConfig` for simulating the controllers' behavior. | ||
It can be used to also simulate part of a small cluster: For example, the following command would create all the connections | ||
needed to run a simulation on 'con1', 'con4', 'con5' which are part of a 9 OPX cluster: `create_simulator_controller_connections(9, [1,4,5])` | ||
|
||
### Usage example | ||
A simple example for a 3 OPX cluster: | ||
```python | ||
from qualang_tools.simulator import create_simulator_controller_connections | ||
|
||
with program() as prog: | ||
# QUA program | ||
|
||
qmm = QuantumMachinesManager(host=qop_ip, port=qop_port, cluster_name=cluster_name) | ||
job = qmm.simulate(config, | ||
prog, | ||
SimulationConfig(simulation_duration, | ||
controller_connections=create_simulator_controller_connections(3))) | ||
``` | ||
|
||
A simulation running on 'con1', 'con4', 'con5' which are part of a 9 OPX cluster, which also has loopback connected between the controllers: | ||
```python | ||
from qualang_tools.simulator import create_simulator_controller_connections | ||
|
||
with program() as prog: | ||
# QUA program | ||
|
||
qmm = QuantumMachinesManager(host=qop_ip, port=qop_port, cluster_name=cluster_name) | ||
job = qmm.simulate(config, | ||
prog, | ||
SimulationConfig(simulation_duration, | ||
simulation_interface=LoopbackInterface([('con1', 1, 'con4', 1), | ||
('con1', 2, 'con4', 2), | ||
('con4', 1, 'con1', 1), | ||
('con4', 2, 'con1', 2), | ||
], | ||
latency=168), | ||
controller_connections=create_simulator_controller_connections(9, [1,4,5]))) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from qualang_tools.simulator.simulator import create_simulator_controller_connections | ||
|
||
__all__ = [ | ||
"create_simulator_controller_connections", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import numpy as np | ||
from qm import ControllerConnection, InterOpxChannel | ||
|
||
|
||
def create_simulator_controller_connections( | ||
n_controllers, actual_controllers=None, n_connections=12, print_debug=False | ||
): | ||
""" | ||
Creates a list of :class:`~qm.simulate.interface.ControllerConnection` objects with the Inter-controllers | ||
connections between controllers in a way which maximizes the optical links connectivity. | ||
For use inside the :class:`~qm.simulate.interface.SimulationConfig` for simulating the controllers` behavior. | ||
:param n_controllers: The number of controllers | ||
:type n_controllers: int | ||
:param actual_controllers: A list of the controllers actually being used in the simulation. For `con1` & `con2` use [1,2]. | ||
:type actual_controllers: List[int] | ||
:param n_connections: The number of optical connectors each controller has, default is 12 | ||
:type n_connections: int | ||
:param print_debug: If true, prints the connections to the terminal | ||
:type print_debug: bool | ||
:returns: The ControllerConnection object | ||
""" | ||
if n_controllers == 1: | ||
return [] | ||
if not actual_controllers: | ||
actual_controllers = [i + 1 for i in range(n_controllers)] | ||
controller_connections = [] | ||
unused_connection = np.ones((n_controllers, n_connections), dtype=bool) | ||
while unused_connection.any(): | ||
for i in range(n_controllers): | ||
for j in range(i + 1, n_controllers): | ||
first_con_port = np.nonzero(unused_connection[i, :])[0] | ||
if first_con_port.size == 0: | ||
break | ||
first_con_port = first_con_port[0] | ||
second_con_port = np.nonzero(unused_connection[j, :])[0] | ||
if second_con_port.size == 0: | ||
break | ||
second_con_port = second_con_port[0] | ||
if i + 1 in actual_controllers and j + 1 in actual_controllers: | ||
controller_connections.append( | ||
ControllerConnection( | ||
InterOpxChannel(f"con{i+1}", first_con_port), InterOpxChannel(f"con{j+1}", second_con_port) | ||
) | ||
) | ||
if print_debug: | ||
print(f"con{i + 1}:{first_con_port} <-> con{j + 1}, {second_con_port}") | ||
elif print_debug: | ||
print(f"con{i + 1}:{first_con_port} <-> con{j + 1}, {second_con_port} - Skipped") | ||
unused_connection[i, first_con_port] = False | ||
unused_connection[j, second_con_port] = False | ||
|
||
return controller_connections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,14 @@ | ||
from qm import ControllerConnection, InterOpxChannel | ||
|
||
|
||
def create_simulator_controller_connections(n_controllers, n_connections=12): | ||
""" | ||
Creates a list of :class:`~qm.simulate.interface.ControllerConnection` objects with all of the Inter-controllers | ||
connections according to the `recommended schema | ||
<https://qm-docs.qualang.io/hardware/opx+installation#inter-controller-optical-connectivity-scheme>`__. | ||
For use inside the :class:`~qm.simulate.interface.SimulationConfig` for simulating the controllers` behavior. | ||
:param n_controllers: The number of controllers | ||
:type n_controllers: int | ||
:param n_connections: The number of optical connectors each controller has, default is 12 | ||
:type n_connections: int | ||
:returns: The ControllerConnection object | ||
""" | ||
if n_controllers == 1: | ||
return None | ||
|
||
ncbc = n_connections // (n_controllers - 1) # ncbc = number_of_connections_between_controllers | ||
n_connections = ncbc * (n_controllers - 1) | ||
first_controller_list = [] | ||
first_port_list = [] | ||
second_controller_list = [] | ||
second_port_list = [] | ||
for i in range(n_controllers): | ||
first_controller_list = first_controller_list + [i + 1] * (n_connections - i * ncbc) | ||
|
||
first_port_list = first_port_list + [j for j in range(i * ncbc, n_connections)] | ||
|
||
for j in range(i + 1, n_controllers): | ||
second_controller_list = second_controller_list + [j + 1] * ncbc | ||
|
||
second_port_list = second_port_list + [j for j in range(i * ncbc, (i + 1) * ncbc)] * (n_controllers - i - 1) | ||
|
||
controller_connections = [ | ||
ControllerConnection(InterOpxChannel(f"con{i}", j), InterOpxChannel(f"con{k}", l)) | ||
for i, j, k, l in list( | ||
zip( | ||
first_controller_list, | ||
first_port_list, | ||
second_controller_list, | ||
second_port_list, | ||
) | ||
) | ||
] | ||
|
||
return controller_connections | ||
from qualang_tools.simulator import create_simulator_controller_connections | ||
import warnings | ||
|
||
__all__ = [ | ||
"create_simulator_controller_connections", | ||
] | ||
|
||
warnings.warn( | ||
"The 'create_simulator_controller_connections' function has been moved to 'qualang_tools.simulator'.", FutureWarning | ||
) | ||
warnings.warn( | ||
"The 'create_simulator_controller_connections' function has been moved to 'qualang_tools.simulator'.", | ||
DeprecationWarning, | ||
) |
Oops, something went wrong.