# All angles of rotations are random. However once the circuit we want to simulate # is determined, there is no stochasticity in the rotation angles across the ensemble. # The rotation angles must therefore be given as *pool* random numbers. num_qubits = 8 x_angles = rng.GetUniformRandomNumbers(num_qubits, 0., np.pi, "pool") y_angles = rng.GetUniformRandomNumbers(num_qubits, 0., np.pi, "pool") z_angles = rng.GetUniformRandomNumbers(num_qubits, 0., np.pi, "pool") if False: info(x_angles) info(y_angles) info(z_angles) # Ideal (i.e. noiseless) state. # |psi> = |00000000> psi = iqs.QubitRegister(num_qubits, "base", 0, 0) # At this point we have one copy of the ideal state for each state in the pool. info("\n---- ideal circuit \n") for q in range(num_qubits): psi.ApplyRotationX(q, x_angles[q]) psi.ApplyRotationY(q, y_angles[q]) psi.ApplyRotationZ(q, z_angles[q]) iqs.MPIEnvironment.PoolBarrier() # Compute the probability of qubit 0 to be in |1>. probability = psi.GetProbability(0) ################################################################################# # Quantum state evolution in presence of noise
#------------------------------------------------ #- Initialize the MPI environment --------------- #------------------------------------------------ comm = MPI.COMM_WORLD print(f'Hi from {comm.Get_rank()}/{comm.Get_size()}') #------------------------------------------------ #- Quantum Simulation --------------------------- #------------------------------------------------ print("\nCreation of the QuantumRegister object.") num_qubits = 2 qreg = simulator.QubitRegister(num_qubits, "base", 0, 0) print("\nInitialize to |1>|0>.") qreg.Initialize("base", 1) print("Apply X(0) to obtain state |0>|0>.") qreg.ApplyPauliX(0) print( "Get probabilities :\n q(0) has prob. {} to be in |1>\n q(1) has prob. {} to be in |1>" .format(qreg.GetProbability(0), qreg.GetProbability(1))) print("Print state:") qreg.Print("State should be |00>") #------------------------------------------------
def run_circuit(num_qubits): reg = iqs.QubitRegister(num_qubits, 'base', 0, 0) for i in range(num_qubits): reg.ApplyHadamard(i) reg.ApplyRotationZ(i, np.pi / 3) return reg
if iqs.MPIEnvironment.IsUsefulRank() == False: iqs.EnvFinalize() exit() # The simulation of a N-qubit system cannot be divided in more than 2^(N-1) ranks. num_qubits = 4 # number of qubits if iqs.MPIEnvironment.GetStateSize() > 2**(num_qubits - 1) or num_qubits < 1: if iqs.MPIEnvironment.GetRank() == 0: print("No more than 2^(N-1) useful ranks for a N-qubit state.") iqs.EnvFinalize() exit() # Prapare the initial state index = 1 * 0 + 1 * 2 + 0 * 4 + 1 * 8 psi = iqs.QubitRegister(num_qubits, 'base', index, 0) # |psi> = |1010> psi.ApplyHadamard(2) # |psi> = |1+10> psi.ApplyHadamard(3) # |psi> = |-+10> # Associate a random-number-generator to the state rng = iqs.RandomNumberGenerator() rng_seed = 7777 rng.SetSeedStreamPtrs(rng_seed) # Get the chi-matrix of the channel chi = get_chi_matrix(channel_type, p_for_channel) if myrank == 0: chi.Print(True) # parameter of the evolution collective_list = []
# Python script to test the successful import of the full stack library import sys sys.path.insert(0, "../build/lib/") import intelqs_py as iqs iqs.EnvInit() rank = iqs.MPIEnvironment.GetRank() print("Creation of a 2-qubit state at rank {}", format(rank)) psi = iqs.QubitRegister(2, "base", 0, 0) print("The IQS library was successfully imported and initialized.") iqs.EnvFinalize()
# Utility function to print a message from the master process only. def info(message): if iqs.MPIEnvironment.GetPoolRank( ) == 0 and iqs.MPIEnvironment.IsUsefulRank(): print(message, flush=True) #------------------------------------------------ #- Quantum Simulation --------------------------- #------------------------------------------------ info("\n ---- Creation of the QuantumRegister object.") num_qubits = 2 qreg = iqs.QubitRegister(num_qubits, "base", 0, 0) info("\n ---- Initialize to |q0>|q1>=|1>|0>.") qreg.Initialize("base", 1) state_vector = np.array(qreg, copy=False) print('\nState amplitudes stored in process {}: {}'.format(rank, state_vector), flush=True) info("\n ---- Apply X(0) to obtain state |0>|0>.") qreg.ApplyPauliX(0) print('\nState amplitudes stored in process {}: {}'.format(rank, state_vector), flush=True) info(