utils module

Collection of functions that might be useful, or might not.

presto.utils.as_flat_list(x)

Return x as a flat unidimensional list.

Parameters

x (object) – An arbitrarily nested list, tuple, np.ndarray, or a mixture thereof.

Returns

A flat, unidimensional list with all the objects of x.

Return type

list

presto.utils.format_sec(s)

Format a time interval in seconds into a more human-readable string.

Parameters

s (float) – time interval in seconds

Returns

time interval in the form “Xh Ym Z.zs”

Return type

str

Examples

>>> format_sec(np.pi * 1e+8)
'9y 348d 20h 27m 45.4s'
>>> format_sec(np.exp(-10))
'45.4us'
presto.utils.get_sourcecode(script_filename)

Open a file and return its content.

Parameters

script_filename (str) – Path to the file.

Returns

a list whose elements are the lines of the file at script_filename

Return type

list of str

presto.utils.rotate_opt(data, return_x=False)

Rotates data so that all the signal is in the I quadrature.

Parameters
  • data (np.ndarray of np.complex128) –

  • return_x (bool, optional) – if True, return also the angle by which data was rotated

Returns

  • ret (np.ndarray of np.complex128) – ret is given by data * np.exp(1j * x), with x such that np.std(ret.imag) is minimum

  • x (float, optional) – angle x, present only if return_x=True

presto.utils.sin2(nr_samples)

Create a \(\sin^2\) envelope/template.

Parameters

nr_samples (int) –

Returns

Return type

np.ndarray of np.float64

presto.utils.sinP(P, nr_samples)

Create a \(\sin^P\) envelope/template.

Parameters
  • P (int) –

  • nr_samples (int) –

Returns

Return type

np.ndarray of np.float64

presto.utils.ssh_connect(address='192.168.42.50', **kwargs)

Connect to the hardware using SSH.

Parameters
Returns

Return type

fabric.connection.Connection

Raises

RuntimeError – if the Python module fabric is not found

presto.utils.ssh_download(remote_filename, local_filename=None, address='192.168.42.50')

Copy a file from the hardware to the local computer.

Parameters
  • remote_filename (str) –

  • local_filename (str, optional) –

  • address (str, optional) – IP address or hostname of the hardware

Returns

Return type

fabric.transfer.Result

Raises

RuntimeError – if the Python module fabric is not found

presto.utils.ssh_execute(command, address='192.168.42.50')

Execute a command on the hardware.

Parameters
  • command (str) –

  • address (str, optional) – IP address or hostname of the hardware

Returns

Return type

fabric.runners.Result

Raises

RuntimeError – if the Python module fabric is not found

presto.utils.ssh_reboot(address='192.168.42.50')

Reboot the Linux system on the hardware.

It is equivalent to ssh_execute(“/sbin/shutdown -r now”).

Parameters

address (str, optional) – IP address or hostname of the hardware

Returns

Return type

fabric.runners.Result

Raises

RuntimeError – if the Python module fabric is not found

presto.utils.ssh_upload(local_filename, remote_filename=None, address='192.168.42.50')

Copy a file from the local computer to the hardware.

Parameters
  • local_filename (str) –

  • remote_filename (str, optional) –

  • address (str, optional) – IP address or hostname of the hardware

Returns

Return type

fabric.transfer.Result

Raises

RuntimeError – if the Python module fabric is not found

presto.utils.to_pm_pi(phase)

Converts a phase in radians into the [-π, +π) interval

Parameters

phase (float or np.ndarray of float) –

Returns

Return type

float or np.ndarray of float

presto.utils.triangle(nr_samples)

Create a triangular envelope/template.

Parameters

nr_samples (int) –

Returns

Return type

np.ndarray of np.float64

presto.utils.untwist_downconversion(I_port, Q_port)

Convert a measured IQ pair into a low/high sideband pair.

Parameters
  • I_port (np.ndarray of np.complex128) –

  • Q_port (np.ndarray of np.complex128) –

Returns

  • L_sideband (np.ndarray of np.complex128)

  • H_sideband (np.ndarray of np.complex128)