Monte Carlo Methods
nisqAE
Functions
- qcware.forge.montecarlo.nisqAE.make_schedule(epsilon: float, schedule_type: str, max_depth: Optional[int] = 20, beta: Optional[float] = 0.5, n_shots: Optional[float] = 20)
Create a schedule for use in the run_nisqAE functions.
Arguments:
- Parameters
epsilon (float) – The additive bound with which to approximate the amplitude
schedule_type (str) – schedule_type in ‘linear’, ‘exponential’, ‘powerlaw’, ‘classical’
max_depth (Optional[int]) – The maximum number of times we should run the iteration circuit (does not affect ‘powerlaw’)., defaults to 20
beta (Optional[float]) – Beta parameter for powerlaw schedule (does not affect other schedule_types)., defaults to 0.5
n_shots (Optional[float]) – Number of measurements to take at each power, defaults to 20
- Returns
A schedule for how many times to run the iteration_circuit, and how many shots to take. A List[Tuple[power, num_shots]], where: - power is the number of times to run the iteration circuit - num_shots is the number of shots to run at the given power
- Return type
Sequence[Tuple[int, int]]
- qcware.forge.montecarlo.nisqAE.run_schedule(initial_circuit: quasar.circuit.Circuit, iteration_circuit: quasar.circuit.Circuit, target_qubits: Sequence[int], target_states: Sequence[int], schedule: Sequence[Tuple[int, int]], backend: str = 'qcware/cpu_simulator')
Run a nisq variant of amplitude estimation and output circuit measurements for each circuit in the given schedule.
Arguments:
- Parameters
initial_circuit (quasar.Circuit) – The oracle circuit whose output we would like to estimate.
iteration_circuit (quasar.Circuit) – The iteration circuit which we will run multiple times according to the schedule.
target_qubits – The qubits which will be measured after every shot and compared to the target_states below.
In the classic amplitude estimation problem, this is usually just [0]. :type target_qubits: Sequence[int]
- Parameters
target_states – The set of states states [in base-10 integer representation] which correspond to “successful” measurements of the target_qubits. If the target_qubits are measured as one of target_states at the end of a shot, target_counts will be incremented.
In the classic amplitude estimation problem, this is usually just [1]. :type target_states: Sequence[int]
- Parameters
schedule (Sequence[Tuple[int, int]]) – A schedule for how many times to run the iteration_circuit, and how many shots to take. A List[Tuple[power, num_shots]], where: - power is the number of times to run the iteration_circuit in a shot - num_shots is the number of shots to run at the given power
backend (str) – String denoting the backend to use, defaults to qcware/cpu_simulator
- Returns
For each element in the schedule, returns a tuple of (element, target_counts), where target_counts is the number of measurements whose outcome is in the set of target_states.
- Return type
Sequence[Tuple[Tuple[int, int], int]]
- qcware.forge.montecarlo.nisqAE.run_unary(circuit: quasar.circuit.Circuit, schedule: Sequence[Tuple[int, int]], backend: str = 'qcware/cpu_simulator')
Performs amplitude estimation routine for unary circuits, assuming the 0th qubit is the target and the target state is |1>, that is, we assume that the state of our system can be written as cos(theta)|0>|badStates> + sin(theta)|1>|0> where badStates is a set of unary states (i.e ones which only one qubit at a time is at state 1) and we’re trying to estimate theta.
Arguments:
- Parameters
circuit (quasar.Circuit) – The oracle circuit whose output we would like to estimate
schedule (Sequence[Tuple[int, int]]) – A schedule for how many times to run the iteration_circuit, and how many shots to take. A List[Tuple[power, num_shots]], where: - power is the number of times to run the iteration circuit - num_shots is the number of shots to run at the given power
backend (str) – String denoting the backend to use, defaults to qcware/cpu_simulator
- Returns
For each element in the schedule, returns a tuple of (element, target_counts), where target_counts is the number of measurements whose outcome is in the set of targetStates.
- Return type
Sequence[Tuple[Tuple[int, int], int]]
- qcware.forge.montecarlo.nisqAE.compute_mle(target_counts: Sequence[Tuple[Tuple[int, int], int]], epsilon: float)
Given the output of the run_nisqAE functions and estimates the parameter theta via MLE.
Arguments:
- Parameters
target_counts (Sequence[Tuple[Tuple[int, int], int]]) – For each element in the schedule, returns a tuple of (element, target_counts), where target_counts is the number of measurements whose outcome is in the set of targetStates.
epsilon (float) – The additive error within which we would like to calculate theta.
- Returns
MLE estimate of theta.
- Return type
float