Beispiel #1
0
 def test_full_vs_reverse_linear(self, num_qubits):
     """Test that 'full' and 'reverse_linear' provide the same unitary element."""
     reps = 2
     full = RealAmplitudes(num_qubits=num_qubits,
                           entanglement="full",
                           reps=reps)
     num_params = (reps + 1) * num_qubits
     np.random.seed(num_qubits)
     params = np.random.rand(num_params)
     reverse = RealAmplitudes(num_qubits=num_qubits,
                              entanglement="reverse_linear",
                              reps=reps)
     full.assign_parameters(params, inplace=True)
     reverse.assign_parameters(params, inplace=True)
     assert Operator(full) == Operator(reverse)
Beispiel #2
0
for i in range(sum(num_qubits)):
    entangler_map.append([i, int(np.mod(i+1, sum(num_qubits)))])

# Load the trained circuit parameters
g_params = [0.29399714, 0.38853322, 0.9557694, 0.07245791, 6.02626428, 0.13537225]

# Set an initial state for the generator circuit
init_dist = NormalDistribution(sum(num_qubits), mu=1., sigma=1., low=bounds[0], high=bounds[1])
init_distribution = np.sqrt(init_dist.probabilities)
init_distribution = Custom(num_qubits=sum(num_qubits), state_vector=init_distribution)

# construct the variational form
var_form = RealAmplitudes(sum(num_qubits), entanglement=entangler_map, reps=1, initial_state=init_distribution)
var_form.entanglement_blocks = 'cz'
theta = ParameterVector('θ', var_form.num_parameters)
var_form = var_form.assign_parameters(theta)

# Set generator circuit
g_circuit = UnivariateVariationalDistribution(sum(num_qubits), var_form, g_params,
                                              low=bounds[0], high=bounds[1])
g_circuit._var_form_params = theta

# construct circuit factory for uncertainty model
uncertainty_model = g_circuit


# set the strike price (should be within the low and the high value of the uncertainty)
strike_price = 2

# set the approximation scaling for the payoff function
c_approx = 0.25