Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/base qcvv framework #992

Merged
merged 31 commits into from
Aug 13, 2024
Merged

Feature/base qcvv framework #992

merged 31 commits into from
Aug 13, 2024

Conversation

cdbf1
Copy link
Contributor

@cdbf1 cdbf1 commented Jul 15, 2024

In preparation for the XEB/IRB benchmarking routines, this PR implements some common functionality that can form the basis of a wide QCVV within superstaq.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@cdbf1 cdbf1 force-pushed the feature/base_qcvv_framework branch from bc42a9e to 0de866f Compare July 16, 2024 08:34
@cdbf1 cdbf1 force-pushed the feature/base_qcvv_framework branch from 47de35b to 0aa0d41 Compare July 18, 2024 16:06
Copy link
Contributor Author

@cdbf1 cdbf1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved qcvv folder to supermarq following discussion at dev meeting

Copy link
Contributor

@richrines1 richrines1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(adding a few comments/questions)

supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
@cdbf1 cdbf1 requested a review from dowusu-antwi July 31, 2024 12:35
@cdbf1 cdbf1 requested a review from richrines1 July 31, 2024 12:35
cirq-superstaq/cirq_superstaq/job_test.py Outdated Show resolved Hide resolved
cirq-superstaq/cirq_superstaq/job_test.py Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
cirq-superstaq/cirq_superstaq/job.py Outdated Show resolved Hide resolved
cirq-superstaq/cirq_superstaq/job.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
Copy link
Contributor

@richrines1 richrines1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, just a couple more questions

not necessarily in this pr, but we'll probably also want to add a third path for experiments on local hardware: in this case we would still use superstaq to compile (but not submit) all the circuits, and then lets the user run the compiled circuits locally and pass in their counts back in to the experiment for analysis

@cdbf1
Copy link
Contributor Author

cdbf1 commented Aug 9, 2024

not necessarily in this pr, but we'll probably also want to add a third path for experiments on local hardware: in this case we would still use superstaq to compile (but not submit) all the circuits, and then lets the user run the compiled circuits locally and pass in their counts back in to the experiment for analysis

Definitely a good shout. A hacky way to do this at the moment would be for the user to use the _build_circuits() method to build the samples and then process them separately. Adding the option to compile them would be cool too, and I guess ideally a slick handle for the users to pass in connection to their own hardware would be the dream - definitely a separate PR though!

@richrines1
Copy link
Contributor

^ sounds good! we'll definitely need something like this for testbed users (e.g. aqt and qscout) who use superstaq to compile but don't have cloud-accessible machines. having a slick interface for this would be really nice

@cdbf1
Copy link
Contributor Author

cdbf1 commented Aug 12, 2024

^ sounds good! we'll definitely need something like this for testbed users (e.g. aqt and qscout) who use superstaq to compile but don't have cloud-accessible machines. having a slick interface for this would be really nice

I've implemented this by separating out the prepare_experiment function from the run function and added a compile method which will compile the circuits to the desired target (with additional optimization options). Then I've added an additional run_with_callable method which allows a custom callable to be used to evaluate each circuit which could in principal be used to run circuits on some local device

@cdbf1 cdbf1 force-pushed the feature/base_qcvv_framework branch from 7f35711 to 86d2afb Compare August 12, 2024 13:46
@cdbf1 cdbf1 force-pushed the feature/base_qcvv_framework branch from 86d2afb to 5c49765 Compare August 12, 2024 13:47
Comment on lines +290 to +295
probabilities = {
format(idx, f"0{self.num_qubits}b"): 0.0 for idx in range(2**self.num_qubits)
}

for key, count in counts.items():
probabilities[key] = count / total
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use

Suggested change
probabilities = {
format(idx, f"0{self.num_qubits}b"): 0.0 for idx in range(2**self.num_qubits)
}
for key, count in counts.items():
probabilities[key] = count / total
probabilities = {key: count / total for key, count in counts.items()}

?

we shouldn't need to include all the keys with no counts in the dictionary (/if we do we should just use an array)

Copy link
Contributor Author

@cdbf1 cdbf1 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of they way these probability dictionaries are treated as records in a dataframe in the various implementations of actual experiments (see for example the qcvv_css.ipynb), to avoid NaNs I prefer enforcing that all the bitstrings are present in the dictionary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sounds good. in that case i think we also need to fill in the missing values in the simulator output?

Comment on lines 582 to 585
if sorted(probability.keys()) != sorted(
f"{i:0{self.num_qubits}b}" for i in range(2**self.num_qubits)
):
raise RuntimeError("Returned probabilities are missing bitstrings.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly here: can we remove this restriction? possibly with some validation, e.g.

Suggested change
if sorted(probability.keys()) != sorted(
f"{i:0{self.num_qubits}b}" for i in range(2**self.num_qubits)
):
raise RuntimeError("Returned probabilities are missing bitstrings.")
probability = circuit_eval_func(sample.circuit, **kwargs)
if not all(len(key) == self.num_qubits for key in probability.keys()):
raise RuntimeError("Returned probabilities include an incorrect number of bits.")

Copy link
Contributor Author

@cdbf1 cdbf1 Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this way of checking that the bit strings are correct, and rather than enforcing that all probabilities are included I've manually set any missing bitstrings to have zero probability. However, as above (for purposes of making into a dataframe nicely, I prefer to make sure that the probabilities are stored in a dictionary with all the possible bitstrings as keys

job: css.Job | None = None
"""The superstaq job corresponding to the sample. Defaults to None if no job is
associated with the sample."""
raw_circuit: cirq.Circuit = field(init=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we make this

Suggested change
raw_circuit: cirq.Circuit = field(init=False)
compiled_circuit: cirq.Circuit = field(init=False)

so we're not redefining circuit in some cases (and to make it more consistent with css.Job)

we can also get the compiled circuits for jobs submitted to hardware via job.compiled_circuits()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone for a mix of both here. The Sample object now has explicitly as raw_circuit (used in the init) and a compiled_circuit attribute. By default we want to use the compiled circuit if it exists, so the circuit property returns exactly this.

In the run_on_device() method, I've also now added a line that updates the compiled circuit for each sample by retrieving it from the css.Job.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, makes sense to me

supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
supermarq-benchmarks/supermarq/qcvv/base_experiment.py Outdated Show resolved Hide resolved
@cdbf1 cdbf1 force-pushed the feature/base_qcvv_framework branch from e944a1d to 574095e Compare August 13, 2024 09:13
Copy link
Contributor

@richrines1 richrines1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, this looks great to me % that simulator output fix (if necessary) :)

@cdbf1
Copy link
Contributor Author

cdbf1 commented Aug 13, 2024

Thanks for all your help @richrines1 - I think we've got something really nice here!

@cdbf1 cdbf1 merged commit ab0802d into main Aug 13, 2024
19 checks passed
@cdbf1 cdbf1 deleted the feature/base_qcvv_framework branch August 13, 2024 16:21
cdbf1 added a commit that referenced this pull request Aug 16, 2024
Implement the XEB routine within the QCVV experiment framework.

Blocked by #992
cdbf1 added a commit that referenced this pull request Sep 6, 2024
Implement the interleaved randomized benchmarking routine within the
qcvv framework.

Blocked by #992
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants