API documentation

Conversion from pytket to qujax circuits

Methods to allow conversion between qujax and pytket

pytket.extensions.qujax.qujax_convert.print_circuit(circuit, symbol_map=None, qubit_min=0, qubit_max=inf, gate_ind_min=0, gate_ind_max=inf, sep_length=1)[source]

Returns and prints basic string representation of circuit.

For more information on the symbol_map parameter refer to the tk_to_qujax or tk_to_qujax_args documentation.

Parameters:
  • circuit (pytket.Circuit) – Circuit to be converted (without any measurement commands).

  • symbol_map (Optional[dict]) –

    If None, parameterised gates determined by qujax.gates.

    If dict, maps symbolic pytket parameters following the order in this dict.

  • qubit_min (int) – Index of first qubit to display.

  • qubit_max (int) – Index of final qubit to display.

  • gate_ind_min (int) – Index of gate to start circuit printing.

  • gate_ind_max (int) – Index of gate to stop circuit printing.

  • sep_length (int) – Number of dashes to separate gates.

Returns:

String representation of circuit

Return type:

List[str]

pytket.extensions.qujax.qujax_convert.qujax_args_to_tk(gate_seq, qubit_inds_seq, param_inds_seq, n_qubits=None, param=None)[source]

Convert qujax args into pytket Circuit.

Parameters:
  • gate_seq (Sequence[str]) – Sequence of gates. Each element is a string matching an array or function in qujax.gates

  • qubit_inds_seq (Sequence[Sequence[int]]) – Sequences of qubits (ints) that gates are acting on.

  • param_inds_seq (Sequence[Sequence[int]]) – Sequence of parameter indices that gates are using, i.e. [[0], [], [5, 2]] tells qujax that the first gate uses the first parameter, the second gate is not parameterised and the third gates used the fifth and second parameters.

  • n_qubits (int) – Number of qubits, if fixed.

  • param (jnp.ndarray) – Circuit parameters, if parameterised. Defaults to all zeroes.

Returns:

Circuit

Return type:

pytket.Circuit

pytket.extensions.qujax.qujax_convert.tk_to_param(circuit)[source]

Extract the parameter vector for non-symbolic circuits. i.e. an array where each element corresponds to the parameter of a parameterised gate found in the circuit

Parameters:

circuit (pytket.Circuit) – Circuit to be converted (without any measurement commands or symbolic gates).

Returns:

1D array containing values of parameters

Return type:

jnp.ndarray

pytket.extensions.qujax.qujax_convert.tk_to_qujax(circuit, symbol_map=None, simulator='statetensor')[source]

Converts a pytket circuit into a function that maps circuit parameters to a statetensor (or densitytensor). Assumes all circuit gates can be found in qujax.gates. The symbol_map argument controls the interpretation of any symbolic parameters found in circuit.free_symbols().

  • If symbol_map is None, circuit.free_symbols() will be ignored. Parameterised gates will be determined based on whether they are stored as functions (parameterised) or arrays (non-parameterised) in qujax.gates. The order of qujax circuit parameters is the same as in circuit.get_commands().

  • If symbol_map is provided as a dict, assign qujax circuit parameters to symbolic parameters in circuit.free_symbols(); the order of qujax circuit parameters will be given by this dict. Keys of the dict should be symbolic pytket parameters as in circuit.free_symbols() and the values indicate the index of the qujax circuit parameter – integer indices starting from 0.

The conversion can be checked by examining the output from tk_to_qujax_args or print_circuit.

Parameters:
  • circuit (pytket.Circuit) – Circuit to be converted (without any measurement commands).

  • symbol_map (Optional[dict]) –

    If None, parameterised gates determined by qujax.gates.

    If dict, maps symbolic pytket parameters following the order in this dict.

  • simulator (str) – string in (‘statetensor’, ‘densitytensor’, ‘unitarytensor’) corresponding to qujax simulator type. Defaults to statetensor.

Returns:

Function which maps parameters (and optional statetensor_in) to a statetensor. If the circuit has no parameters, the resulting function will only take the optional statetensor_in as an argument.

Return type:

Callable[[jnp.ndarray, jnp.ndarray = None], jnp.ndarray] or Callable[[jnp.ndarray = None], jnp.ndarray] if no parameters found in circuit

pytket.extensions.qujax.qujax_convert.tk_to_qujax_args(circuit, symbol_map=None)[source]

Converts a pytket circuit into a tuple of arguments representing a qujax quantum circuit. Assumes all circuit gates can be found in qujax.gates The symbol_map argument controls the interpretation of any symbolic parameters found in circuit.free_symbols().

  • If symbol_map is None, circuit.free_symbols() will be ignored. Parameterised gates will be determined based on whether they are stored as functions (parameterised) or arrays (non-parameterised) in qujax.gates. The order of qujax circuit parameters is the same as in circuit.get_commands().

  • If symbol_map is provided as a dict, assign qujax circuit parameters to symbolic parameters in circuit.free_symbols(); the order of qujax circuit parameters will be given by this dict. Keys of the dict should be symbolic pytket parameters as in circuit.free_symbols() and the values indicate the index of the qujax circuit parameter – integer indices starting from 0.

The conversion can also be checked with print_circuit.

Parameters:
  • circuit (pytket.Circuit) – Circuit to be converted (without any measurement commands).

  • symbol_map (Optional[dict]) –

    If None, parameterised gates determined by qujax.gates.

    If dict, maps symbolic pytket parameters following the order in this dict.

Returns:

Tuple of arguments defining a (parameterised) quantum circuit that can be sent to qujax.get_params_to_statetensor_func. The elements of the tuple (qujax args) are as follows

  • Sequence of gate name strings to be found in qujax.gates.

  • Sequence of sequences describing which qubits gates act on.

  • Sequence of sequences of parameter indices that gates are using.

  • Number of qubits.

Return type:

Tuple[Sequence[str], Sequence[Sequence[int]], Sequence[Sequence[int]], int]