Gates

Here you learn how to use the different gate sets to sample noisy quantum gates. The gate set combines multiple gate factories into a single object, which is easy to import and pass in arguments.

Usage

While the usage is fairly trivial, there is one dangerous subtlety that the user should be aware of. As computer programs are deterministic, the sampling from probability distributions often works by using a pseudo-random number generator underneath. Thus, the user should not accidentaly sample the same gates multiple times, which can happen when the same simulation is run in parallel many times, and the seed of the pseudo-random number generator is the same in each run. An easy fix would be to set a random seed in the start of each simulation.

# Set random seed, otherwise each experiment gets the same result
seed = (os.getpid() * int(time.time())) % 123456789
np.random.seed(seed)

Another method would be to pass the seed to the simulation. When reproducability of the simulation results is important, then this is the better option. Note how the seed is set inside the simulation and not outside.

import multiprocessing

def simulation(seed) -> float:
    """ Returns a random number in [0, 1] for a specific random seed. """
    np.random.seed(seed)
    return np.random.rand(1)

args = range(100)
p = multiprocessing.Pool(4)

for result in p.imap_unordered(func=simulation, iterable=args, chunksize=100//4):
    print(f"Result: {result}")

Note that this possible issue is specific to multiprocessing on Linux operating system, as it depends on how new processes are created.

Instances and Classes

The Gates classes and instances provide a consistent interface for sampling noisy gates.

At the moment, we support the following gates: X, SX, CR, CNOT, CNOT_inv, SingleQubitGate. Note that Rz gates are virtual on superconducting devices by IBM.

quantum_gates.gates.standard_gates[source]

Gates produced with constant pulses, the integrations are based on analytical solutions.

Type:

Gates

quantum_gates.gates.numerical_gates[source]

Gates produced with constant pulses, but the integrations are performed numerically.

Type:

Gates

quantum_gates.gates.noise_free_gates[source]

Gates in the noise free case, based on solving the equations analytically.

Type:

NoiseFreeGates

quantum_gates.gates.almost_noise_free_gates[source]

Gates in the noise free case, but based on scaling the noise down.

Type:

ScaledNoiseGates

class quantum_gates.gates.Gates(pulse: ~quantum_gates._gates.pulse.Pulse = <quantum_gates._gates.pulse.ConstantPulse object>)[source]

Bases: object

Collection of the gates. Handles adding the pulse shape to the gates.

This way, we do not have to pass the pulse shape each time we generate a gate.

Example

from quantum_gates.pulses import GaussianPulse
from quantum_gates.gates import Gates

pulse = GaussianPulse(loc=1, scale=1)
gateset = Gates(pulse)

sampled_x = gateset.X(phi, p, T1, T2)
Parameters:

pulse (Pulse) –

relaxation(Dt, T1, T2) array[source]
Return type:

array

bitflip(Dt, p) array[source]
Return type:

array

depolarizing(Dt, p) array[source]
Return type:

array

single_qubit_gate(theta, phi, p, T1, T2) array[source]
Return type:

array

X(phi, p, T1, T2) array[source]
Return type:

array

SX(phi, p, T1, T2) array[source]
Return type:

array

CR(theta, phi, t_cr, p_cr, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

CNOT(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

CNOT_inv(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

class quantum_gates.gates.NoiseFreeGates[source]

Bases: object

Version of Gates for the noiseless case.

Has the same interface as the Gates class, but ignores the arguments specifying the noise.

Example

from quantum_gates.gates import NoiseFreeGates

gateset = NoiseFreeGates()
sampled_x = gateset.X(phi, p, T1, T2)
relaxation(Dt, T1, T2) array[source]

Returns single qubit relaxation in noise free regime -> identity.

Return type:

array

bitflip(Dt, p) array[source]

Returns single qubit bitflip in noise free regime -> identity.

Return type:

array

depolarizing(Dt, p) array[source]

Returns single qubit depolarizing in noise free regime -> identity.

Return type:

array

single_qubit_gate(theta, phi, p, T1, T2)[source]

Returns general single qubit gate in noise free regime.

X(phi, p, T1, T2) array[source]

Returns X gate in noise free regime.

Return type:

array

SX(phi, p, T1, T2) array[source]

Returns SX gate in noise free regime.

Return type:

array

CNOT(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]

Returns CNOT gate in noise free regime.

Return type:

array

CNOT_inv(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]

Returns CNOT inverse gate in noise free regime.

Return type:

array

CR(theta, phi, t_cr, p_cr, T1_ctr, T2_ctr, T1_trg, T2_trg)[source]

Returns CR gate in noise free regime.

class quantum_gates.gates.ScaledNoiseGates(noise_scaling: float, pulse: ~quantum_gates._gates.pulse.Pulse = <quantum_gates._gates.pulse.ConstantPulse object>)[source]

Bases: object

Version of Gates in which the noise is scaled by a certain factor noise_scale of at least 1e-15.

The smaller the noise_scaling value, the less noisy the gates are.

Examples

from quantum_gates.gates import ScaledNoiseGates

gateset = ScaledNoiseGates(noise_scaling=0.1, pulse=pulse)  # 10x less noise
sampled_x = gateset.X(phi, p, T1, T2)
Parameters:
relaxation(Dt, T1, T2) array[source]
Return type:

array

bitflip(Dt, p) array[source]
Return type:

array

depolarizing(Dt, p) array[source]
Return type:

array

single_qubit_gate(theta, phi, p, T1, T2) array[source]
Return type:

array

X(phi, p, T1, T2) array[source]
Return type:

array

SX(phi, p, T1, T2) array[source]
Return type:

array

CR(theta, phi, t_cr, p_cr, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

CNOT(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

CNOT_inv(phi_ctr, phi_trg, t_cnot, p_cnot, p_single_ctr, p_single_trg, T1_ctr, T2_ctr, T1_trg, T2_trg) array[source]
Return type:

array

quantum_gates.gates.legacy_gates[source]

alias of LegacyGates