qubiter.CGateExpander module

class qubiter.CGateExpander.CGateExpander(file_prefix, num_qbits, **kwargs)[source]

Bases: qubiter.SEO_reader.SEO_reader

Qubiter English and Picture files allow single lines that represent U(2) matrices of numerous types with 0, 1 or multiple controls of either the n or nbar kind. If we say a gate is controlled, it may have 1 or more controls (it might be singly or multiply controlled). This class is a child of SEO_reader. The class reads any previously created Qubiter English file and it writes new English & Picture files wherein every line of the original English file is expanded into a sequence of (1) single qubit rotations and (2) simple CNOTs. Such a class is useful because many quantum computers (for example, IBM Quantum Experience) can only do (1) and (2).

If the input English file has file_prefix as file prefix, then the output English & Picture files have as file prefix file_prefix + ‘_X1’, assuming that ‘_X’ + str(k) for some integer k is not already the ending of file_prefix. If it is, then the ending is changed to ‘_X’ + str( k+1).

Global phase factors are ignored, so expansions equal the original line up to a phase factor.

You can get a count of the number of CNOTs in the expanded file by creating an object of the class SEO_reader.

Variables:wr (CGateSEO_writer) – This object of CGateSEO_writer, created in the class constructor, is called inside every use_ function to do some writing in the output files.
__init__(file_prefix, num_qbits, **kwargs)[source]

Constructor

Parameters:
  • file_prefix (str) –
  • num_qbits (int) –
do_log()[source]

This class does a “flat” reading of the input file; i.e., the reading does not respect loop structure. Hence, we won’t let it write a log file, for if we did, it would be incorrect. A correct log file can always be obtained by creating a SEO_reader object.

Returns:
Return type:None
emb_for_c_u2(tar_bit_pos, controls)[source]

This internal function returns a CktEmbedder object called emb that is used to write an expansion for a controlled U(2) matrix with target at tar_bit_pos.

Parameters:
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

CktEmbedder

two_embs_for_c_qbit_swap(bit1, bit2, controls)[source]

This internal function returns two CktEmbedder objects called emb0, emb1 that are used to write an expansion for a controlled swap of bits bit1, bit2.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
Returns:

Return type:

(CktEmbedder, CktEmbedder)

use_DIAG(trols, rad_angles)[source]

Returns error message if input circuit contains diagonal unitaries DIAG.

Parameters:
  • trols (Controls) –
  • rad_angles (list[float]) –
use_HAD2(tar_bit_pos, controls)[source]

This function expands a HAD2 line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_IF_M_beg(controls)[source]

This function echoes IF_M_beg line.

Parameters:controls (Controls) –
Returns:
Return type:None
use_IF_M_end()[source]

This function echoes IF_M_end line

Returns:
Return type:None
use_LOOP(loop_num, nreps)[source]

This function echoes a LOOP line; i.e., it transcribes the line from the input English file to the output English & Picture files.

Parameters:
  • loop_num (int) –
  • nreps (int) –
Returns:

Return type:

None

use_MEAS(tar_bit_pos, kind)[source]

This function echoes a MEAS line; i.e., it transcribes the line from the input English file to the output English & Picture files.

Parameters:
  • kind (int) –
  • tar_bit_pos (int) –
Returns:

Return type:

None

use_MP_Y(tar_bit_pos, trols, rad_angles)[source]

Returns error message if input circuit contains multiplexors MP_Y.

Parameters:
  • tar_bit_pos (int) –
  • trols (Controls) –
  • rad_angles (list[float]) –
use_NEXT(loop_num)[source]

This function echoes a NEXT line; i.e., it transcribes the line from the input English file to the output English & Picture files.

Parameters:loop_num (int) –
Returns:
Return type:None
use_NOTA(bla_str)[source]

This function echoes a NOTA line; i.e., it transcribes the line from the input English file to the output English & Picture files.

Parameters:bla_str (str) –
Returns:
Return type:None
use_PHAS(angle_rads, tar_bit_pos, controls)[source]

This function expands a PHAS line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_PRINT(style, line_num)[source]

This function echoes a PRINT line; i.e., it transcribes the line from the input English file to the output English & Picture files.

Parameters:
  • style (str) –
  • line_num (int) –
Returns:

Return type:

None

use_P_PH(projection_bit, angle_rads, tar_bit_pos, controls)[source]

This function expands a P0PH or P1PH line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • projection_bit (int) –
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_ROTA(axis, angle_rads, tar_bit_pos, controls)[source]

This function expands a ROTX, ROTY or ROTZ line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • axis (int) –
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_ROTN(angle_x_rads, angle_y_rads, angle_z_rads, tar_bit_pos, controls)[source]

This function expands a ROTN line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • angle_x_rads (float) –
  • angle_y_rads (float) –
  • angle_z_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SIG(axis, tar_bit_pos, controls)[source]

This function expands a SIGX, SIGY or SIGZ line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • axis (int) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SWAP(bit1, bit2, controls)[source]

This function expands a SWAP; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SWAY(bit1, bit2, controls, rads_list)[source]

This function expands a SWAY line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
  • rads_list (list[float]) –
Returns:

Return type:

None

use_SWA_(bit1, bit2, controls, rads_list=None)[source]

This internal function expands a SWAP or SWAY line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
  • rads_list (list[float]) – list of 4 floats
Returns:

Return type:

None

use_U_2_(rads0, rads1, rads2, rads3, tar_bit_pos, controls)[source]

This function expands a U_2_ line; i.e., it reads the line from the input English file and writes an expansion of it in the output English & Picture files.

Parameters:
  • rads0 (float) –
  • rads1 (float) –
  • rads2 (float) –
  • rads3 (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

write_gate_name(name, num_trols)[source]

This function is used solely in the verbose mode. It announces with a NOTA comment line the beginning of a gate expansion.

Parameters:
  • name (str) –
  • num_trols (int) –
Returns:

Return type:

None