API Documentation

C3objs

Basic custom objects.

class c3.c3objs.C3obj(name, desc='', comment='', params=None)[source]

Bases: object

Represents an abstract object with parameters. To be inherited from.

Parameters
  • name (str) – short name that will be used as identifier

  • desc (str) – longer description of the component

  • comment (str) – additional information about the component

  • params (dict) – Parameters in this dict can be accessed and optimized

asdict() dict[source]
class c3.c3objs.Quantity(value, unit='undefined', min_val=None, max_val=None, symbol='\\alpha')[source]

Bases: object

Represents any physical quantity used in the model or the pulse specification. For arithmetic operations just the numeric value is used. The value itself is stored in an optimizer friendly way as a float between -1 and 1. The conversion is given by

scale (value + 1) / 2 + offset

Parameters
  • value (np.array(np.float64) or np.float64) – value of the quantity

  • min_val (np.array(np.float64) or np.float64) – minimum this quantity is allowed to take

  • max_val (np.array(np.float64) or np.float64) – maximum this quantity is allowed to take

  • unit (str) – physical unit

  • symbol (str) – latex representation

add(val)[source]
asdict() dict[source]

Return a config-compatible dictionary representation.

get_limits()[source]
get_opt_value() numpy.ndarray[source]

Get an optimizer friendly representation of the value.

get_value(val: tf.float64 = None, dtype: <module 'tensorflow._api.v2.dtypes' from '/home/docs/checkouts/readthedocs.org/user_builds/c3-toolset/envs/master/lib/python3.7/site-packages/tensorflow/_api/v2/dtypes/__init__.py'> = None) tensorflow.python.framework.ops.Tensor[source]

Return the value of this quantity as tensorflow.

Parameters
  • val (tf.float64) –

  • dtype (tf.dtypes) –

numpy() numpy.ndarray[source]

Return the value of this quantity as numpy.

set_limits(min_val, max_val)[source]
set_opt_value(val: float) None[source]

Set value optimizer friendly.

Parameters

val (tf.float64) – Tensorflow number that will be mapped to a value between -1 and 1.

set_value(val, extend_bounds=False)[source]
subtract(val)[source]
c3.c3objs.hjson_decode(z)[source]
c3.c3objs.hjson_encode(z)[source]
c3.c3objs.jsonify_list(data, transform_arrays=True)[source]

Experiment module

Experiment class that models and simulates the whole experiment.

It combines the information about the model of the quantum device, the control stack and the operations that can be done on the device.

Given this information an experiment run is simulated, returning either processes, states or populations.

class c3.experiment.Experiment(pmap: Optional[c3.parametermap.ParameterMap] = None, prop_method=None)[source]

Bases: object

It models all of the behaviour of the physical experiment, serving as a host for the individual parts making up the experiment.

Parameters

pmap (ParameterMap) –

including model: Model

The underlying physical device.

generator: Generator

The infrastructure for generating and sending control signals to the device.

gateset: GateSet

A gate level description of the operations implemented by control pulses.

asdict() Dict[source]

Return a dictionary compatible with config files.

compute_propagators()[source]

Compute the unitary representation of operations. If no operations are specified in self.opt_gates the complete gateset is computed.

Returns

A dictionary of gate names and their unitary representation.

Return type

dict

compute_states() Dict[c3.signal.gates.Instruction, List[tensorflow.python.framework.ops.Tensor]][source]

Employ a state solver to compute the trajectory of the system.

Returns

List of states of the system from simulation.

Return type

List[tf.tensor]

enable_qasm() None[source]

Switch the sequencing format to QASM. Will become the default.

evaluate_legacy(sequences)[source]

Compute the population values for a given sequence of operations.

Parameters

sequences (str list) – A list of control pulses/gates to perform on the device.

Returns

A list of populations

Return type

list

evaluate_qasm(sequences)[source]

Compute the population values for a given sequence (in QASM format) of operations.

Parameters

sequences (dict list) – A list of control pulses/gates to perform on the device in QASM format.

Returns

A list of populations

Return type

list

expect_oper(state, lindbladian, oper)[source]
from_dict(cfg: Dict) None[source]

Load experiment from dictionary

get_VZ(target, params)[source]

Returns the appropriate Z-rotation.

get_perfect_gates(gate_keys: Optional[list] = None) Dict[str, numpy.ndarray][source]

Return a perfect gateset for the gate_keys.

Parameters

gate_keys (list) – (Optional) List of gates to evaluate.

Returns

A dictionary of gate names and np.array representation of the corresponding unitary

Return type

Dict[str, np.array]

Raises

Exception – Raise general exception for undefined gate

load_quick_setup(filepath: str) None[source]

Load a quick setup file.

Parameters

filepath (str) – Location of the configuration file

lookup_gate(name, qubits, params=None) tensorflow.python.framework.constant_op.constant[source]

Returns a fixed operation or a parametric virtual Z gate. To be extended to general parametric gates.

populations(state, lindbladian)[source]

Compute populations from a state or density vector.

Parameters
  • state (tf.Tensor) – State or densitiy vector.

  • lindbladian (boolean) – Specify if conversion to density matrix is needed.

Returns

Vector of populations.

Return type

tf.Tensor

process(populations, labels=None)[source]

Apply a readout procedure to a population vector. Very specialized at the moment.

Parameters
  • populations (list) – List of populations from evaluating.

  • labels (list) – List of state labels specifying a subspace.

Returns

A list of processed populations.

Return type

list

quick_setup(cfg) None[source]

Load a quick setup cfg and create all necessary components.

Parameters

cfg (Dict) – Configuration options

read_config(filepath: str) None[source]

Load a file and parse it to create a Model object.

Parameters

filepath (str) – Location of the configuration file

set_created_by(config)[source]

Store the config file location used to created this experiment.

set_enable_store_unitaries(flag, logdir, exist_ok=False)[source]

Saving of unitary propagators.

Parameters
  • flag (boolean) – Enable or disable saving.

  • logdir (str) – File path location for the resulting unitaries.

set_opt_gates(gates)[source]

Specify a selection of gates to be computed.

Parameters

gates (Identifiers of the gates of interest. Can contain duplicates.) –

set_opt_gates_seq(seqs)[source]

Specify a selection of gates to be computed.

Parameters

seqs (Identifiers of the sequences of interest. Can contain duplicates.) –

set_prop_method(prop_method=None) None[source]

Configure the selected propagation method by either linking the function handle or looking it up in the library.

store_Udict(goal)[source]

Save unitary as text and pickle.

goal: tf.float64

Value of the goal function, if used.

write_config(filepath: str) None[source]

Write dictionary to a HJSON file.

Model module

The model class, containing information on the system and its modelling.

class c3.model.Model(subsystems=None, couplings=None, tasks=None, max_excitations=0)[source]

Bases: object

What the theorist thinks about from the system.

Class to store information about our system/problem/device. Different models can represent the same system.

Parameters
  • subsystems (list) – List of individual, non-interacting physical components like qubits or resonators

  • couplings (list) – List of interaction operators between subsystems, like couplings or drives.

  • tasks (list) – Badly named list of processing steps like line distortions and read out modeling

  • max_excitations (int) – Allow only up to max_excitations in the system

asdict() dict[source]

Return a dictionary compatible with config files.

blowup_excitations(op)[source]
cut_excitations(op)[source]
fromdict(cfg: dict) None[source]

Load a file and parse it to create a Model object.

Parameters

cfg (dict) – configuration file

get_Frame_Rotation(t_final: numpy.float64, freqs: dict, framechanges: dict)[source]

Compute the frame rotation needed to align Lab frame and rotating Eigenframes of the qubits.

Parameters
  • t_final (tf.float64) – Gate length

  • freqs (list) – Frequencies of the local oscillators.

  • framechanges (list) – List of framechanges. A phase shift applied to the control signal to compensate relative phases of drive oscillator and qubit.

Returns

A (diagonal) propagator that adjust phases

Return type

tf.Tensor

get_Hamiltonian(signal=None)[source]

Get a hamiltonian with an optional signal. This will return an hamiltonian over time. Can be used e.g. for tuning the frequency of a transmon, where the control hamiltonian is not easily accessible. If max.excitation is non-zero the resulting Hamiltonian is cut accordingly

get_Hamiltonians()[source]
get_Lindbladians()[source]
get_dephasing_channel(t_final, amps)[source]

Compute the matrix of the dephasing channel to be applied on the operation.

Parameters
  • t_final (tf.float64) – Duration of the operation.

  • amps (dict of tf.float64) – Dictionary of average amplitude on each drive line.

Returns

Matrix representation of the dephasing channel.

Return type

tf.tensor

get_ground_state() tensorflow.python.framework.constant_op.constant[source]
get_qubit_freqs() List[float][source]
get_sparse_Hamiltonian(signal=None)[source]
get_sparse_Hamiltonians()[source]
get_state_indeces(states: List[Tuple]) List[int][source]
get_state_index(state: Tuple) int[source]
list_parameters()[source]
read_config(filepath: str) None[source]

Load a file and parse it to create a Model object.

Parameters

filepath (str) – Location of the configuration file

set_FR(use_FR)[source]

Setter for the frame rotation option for adjusting the individual rotating frames of qubits when using gate sequences

set_components(subsystems, couplings=None, max_excitations=0) None[source]
set_dephasing_strength(dephasing_strength)[source]
set_dressed(dressed)[source]

Go to a dressed frame where static couplings have been eliminated.

Parameters

dressed (boolean) –

set_lindbladian(lindbladian)[source]

Set whether to include open system dynamics.

Parameters

lindbladian (boolean) –

set_max_excitations(max_excitations) None[source]

Set the maximum number of excitations in the system used for propagation.

set_tasks(tasks) None[source]
update_Hamiltonians()[source]

Recompute the matrix representations of the Hamiltonians.

update_Lindbladians()[source]

Return Lindbladian operators and their prefactors.

update_dressed(ordered=True)[source]

Compute the Hamiltonians in the dressed basis by diagonalizing the drift and applying the resulting transformation to the control Hamiltonians.

update_drift_eigen(ordered=True)[source]

Compute the eigendecomposition of the drift Hamiltonian and store both the Eigenenergies and the transformation matrix.

update_model(ordered=True)[source]
write_config(filepath: str) None[source]

Write dictionary to a HJSON file.

Parameter map

ParameterMap class

class c3.parametermap.ParameterMap(instructions: List[c3.signal.gates.Instruction] = [], generator=None, model=None)[source]

Bases: object

Collects information about control and model parameters and provides different representations depending on use.

asdict(instructions_only=True) dict[source]

Return a dictionary compatible with config files.

check_limits(opt_map)[source]

Check if all elements of equal ids have the same limits. This has to be checked against if setting values optimizer friendly.

Parameters

opt_map

fromdict(cfg: dict) None[source]
get_full_params() Dict[str, c3.c3objs.Quantity][source]

Returns the full parameter vector, including model and control parameters.

get_key_from_scaled_index(idx, opt_map=None) str[source]

Get the key of the value at position ìdx of the scaled_parameters output :param idx: :param opt_map:

get_not_opt_params(opt_map=None) Dict[str, c3.c3objs.Quantity][source]
get_opt_limits()[source]
get_opt_map(opt_map=None) List[List[str]][source]
get_opt_units() List[str][source]

Returns a list of the units of the optimized quantities.

get_parameter(par_id: Tuple[str, ...]) c3.c3objs.Quantity[source]

Return one the current parameters.

Parameters

par_id (tuple) – Hierarchical identifier for parameter.

Returns

Return type

Quantity

get_parameter_dict(opt_map=None) Dict[str, c3.c3objs.Quantity][source]

Return the current parameters in a dictionary including keys. :param opt_map:

Returns

Return type

Dictionary with Quantities

get_parameters(opt_map=None) List[c3.c3objs.Quantity][source]

Return the current parameters.

Parameters

opt_map (list) – Hierarchical identifier for parameters.

Returns

Return type

list of Quantity

get_parameters_scaled(opt_map=None) numpy.ndarray[source]

Return the current parameters. This fuction should only be called by an optimizer. Are you an optimizer?

Parameters

opt_map (tuple) – Hierarchical identifier for parameters.

Returns

Return type

list of Quantity

load_values(init_point)[source]

Load a previous parameter point to start the optimization from.

Parameters

init_point (str) – File location of the initial point

print_parameters(opt_map=None) None[source]

Print current parameters to stdout.

read_config(filepath: str) None[source]

Load a file and parse it to create a ParameterMap object.

Parameters

filepath (str) – Location of the configuration file

set_opt_map(opt_map) None[source]

Set the opt_map, i.e. which parameters will be optimized.

set_parameters(values: Union[List, numpy.ndarray], opt_map=None, extend_bounds=False) None[source]

Set the values in the original instruction class.

Parameters
  • values (list) – List of parameter values. Can be nested, if a parameter is matrix valued.

  • opt_map (list) – Corresponding identifiers for the parameter values.

  • extend_bounds (bool) – If true bounds of quantity objects will be extended.

set_parameters_scaled(values: Union[tensorflow.python.framework.constant_op.constant, tensorflow.python.ops.variables.Variable], opt_map=None) None[source]

Set the values in the original instruction class. This fuction should only be called by an optimizer. Are you an optimizer?

Parameters

values (list) – List of parameter values. Matrix valued parameters need to be flattened.

store_values(path: str, optim_status=None) None[source]

Write current parameter values to file. Stores the numeric values, as well as the names in form of the opt_map and physical units. If an optim_status is given that will be used.

Parameters
  • path (str) – Location of the resulting logfile.

  • optim_status (dict) – Dictionary containing current parameters and goal function value.

str_parameters(opt_map: Optional[Union[List[List[Tuple[str]]], List[List[str]]]] = None) str[source]

Return a multi-line human-readable string of the optmization parameter names and current values.

Parameters

opt_map (list) – Optionally use only the specified parameters.

Returns

Parameters and their values

Return type

str

update_parameters()[source]
write_config(filepath: str) None[source]

Write dictionary to a HJSON file.

Main module

Base script to run the C3 code from a main config file.

c3.main.run_cfg(cfg, opt_config_filename, debug=False)[source]

Execute an optimization problem described in the cfg file.

Parameters
  • cfg (Dict[str, Union[str, int, float]]) – Configuration file containing optimization options and information needed to completely setup the system and optimization problem.

  • debug (bool, optional) – Skip running the actual optimization, by default False

Module contents

Subpackages