pygsti.algorithms.randomcircuit.create_random_circuit

pygsti.algorithms.randomcircuit.create_random_circuit#

create_random_circuit(pspec, length, qubit_labels=None, sampler='Qelimination', samplerargs=None, addlocal=False, lsargs=None, rand_state=None)#

Samples a random circuit of the specified length (or ~ twice this length).

The created circuit’s layers are independently sampled according to the specified sampling distribution.

Parameters:
  • pspec (QubitProcessorSpec) – The QubitProcessorSpec for the device that the circuit is being sampled for. This is always handed to the sampler, as the first argument of the sampler function. Unless qubit_labels is not None, the circuit is sampled over all the qubits in pspec.

  • length (int) – If addlocal is False, this is the length of the sampled circuit. If addlocal is True the length of the circuits is 2*length+1 with odd-indexed layers sampled according to the sampler specified by `sampler, and the the zeroth layer + the even-indexed layers consisting of random 1-qubit gates (with the sampling specified by lsargs)

  • qubit_labels (list, optional) – If not None, a list of the qubits to sample the circuit for. This is a subset of pspec.qubit_labels. If None, the circuit is sampled to act on all the qubits in pspec.

  • sampler (str or function, optional) – If a string, this should be one of: {‘edgegrab’’, ‘Qelimination’, ‘co2Qgates’, ‘local’}. Except for ‘local’, this corresponds to sampling layers according to the sampling function in rb.sampler named circuit_layer_by* (with * replaced by ‘sampler’). For ‘local’, this corresponds to sampling according to rb.sampler.circuit_layer_of_oneQgates. If this is a function, it should be a function that takes as the first argument a QubitProcessorSpec, and returns a random circuit layer as a list of gate Label objects. Note that the default ‘Qelimination’ is not necessarily the most useful in-built sampler, but it is the only sampler that requires no parameters beyond the QubitProcessorSpec and works for arbitrary connectivity devices. See the docstrings for each of these samplers for more information.

  • samplerargs (list, optional) – A list of arguments that are handed to the sampler function, specified by sampler. The first argument handed to the sampler is pspec and samplerargs lists the remaining arguments handed to the sampler. For some in-built samplers this is not optional.

  • addlocal (bool, optional) – If False, the circuit sampled is of length length and each layer is independently sampled according to the sampler specified by sampler. If True, the circuit sampled is of length 2*`length`+1 where: the zeroth + all even layers are consisting of independently random 1-qubit gates (with the sampling specified by lsargs); the odd-indexed layers are independently sampled according to sampler. So length`+1 layers consist only of 1-qubit gates, and `length layers are sampled according to sampler.

  • lsargs (list, optional) – A list of arguments that are handed to the 1-qubit gate layers sampler rb.sampler.circuit_layer_of_oneQgates for the alternating 1-qubit-only layers that are included in the circuit if addlocal is True. This argument is not used if addlocal is false. Note that pspec is used as the first, and only required, argument of rb.sampler.circuit_layer_of_oneQgates. If lsargs = [] then all available 1-qubit gates are uniformly sampled from. To uniformly sample from only a subset of the available 1-qubit gates (e.g., the Paulis to Pauli-frame-randomize) then lsargs should be a 1-element list consisting of a list of the relevant gate names (e.g., lsargs = [‘Gi, ‘Gxpi, ‘Gypi’, ‘Gzpi’]).

  • rand_state (RandomState or int, optional (default None)) – A np.random.RandomState object for seeding RNG. If an integer is passed in this is used to set the seed for a newly constructed RNG.

Returns:

A random circuit of length length (if not addlocal) or length 2*`length`+1 (if addlocal) with layers independently sampled using the specified sampling distribution.

Return type:

Circuit