-
Notifications
You must be signed in to change notification settings - Fork 20
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
[Refactor] Handle all parameters in Context #159
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ters optimization
…in verifier; use serial verifier
The generator is not generating parameter expressions properly now. Fixing later. |
…_json without hash values, fix generator when unique_parameters is false
Fixed now. |
zikun-li
approved these changes
Jan 26, 2024
This was referenced Jan 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #17
This PR is a large-scale refactoring, moving all parameters from
CircuitSeq
toContext
. It will reduce the memory usage of ECC sets.Please review this PR if you are developing on Quartz.
Benchmark for generator on Nam gate set:
Before:
(3,3)-complete:
(4,3)-complete (87.1KiB):
After (slightly worse, will be fixed in the next PR):
(3,3)-complete:
(4,3)-complete (70.1KiB):
Change list:
CircuitSeq
add_gate()
andinsert_gate()
no longer allow creating parameters, andadd_input_parameter()
is removed.get_num_input_parameters(), get_num_total_parameters(), get_num_internal_parameters(), input_param_used()
are removed. Instead, functionsget_input_param_indices(), get_directly_used_param_indices(), get_param_expr_ops()
are added for convenience.remove_unused_input_params()
are removed.add_gate(), insert_gate(), canonical_representation(), to_canonical_representation(), get_gate_permutation(), get_permuted_seq(), clone_from()
now take a context object.evaluate()
does not compute parameters now.remove_gate()
changes fromint
tobool
because it can only remove at most one gate now.get_input_param_mask()
is renamed toget_input_param_usage_mask()
and part of its function is moved toContext
.PhaseShiftIdType
now usesctx->get_num_parameters()
instead ofget_num_total_parameters()
to distinguish different cases.Json
CircuitSeq::to_json()
now adds a flag to keep the hash values in the metadata or not. It no longer contains parameter expressions.CircuitSeq
in Json files no longer containsnum_input_parameters
andnum_total_parameters
.Context
is now in charge of dumping parameter information to Json by the newly added functionsparam_info_to_json()
andload_param_info_from_json()
.Dataset
andEquivalenceSet
are updated correspondingly.CircuitGate::to_json(), read_json()
for convenience.Generator
generate()
no longer takesnum_input_parameters
andmax_num_param_gates
. These should be specified inContext
.generate_parameter_gates()
is moved fromCircuitSeq
toContext
and renamed togenerate_parameter_expressions()
.context
is renamed toctx_
.Generator
now stores a private memberinput_param_masks_
fromContext
for convenience.decltype(std::chrono::steady_clock::now() - std::chrono::steady_clock::now())
is updated tostd::chrono::steady_clock::duration
. This is what it evaluates to.generate()
,bfs()
no longer takesmax_num_param_gates
.Verifier
evaluate()
no longer computes the parameters -- the logic is moved tofind_equivalences()
.equivalent()
.CircuitSeq
.Optimizer
Graph
andGraphXfer
.Graph::to_circuit_sequence()
.constant_param_values
inGraph
, we now recordparam_idx
and store the concrete parameter values inContext
. This keeps theGraph
s convertible toCircuitSeq
s.get_param_value()
andparam_has_value()
which should be easier to update if the API is going to change again in the future.Context
get_and_gen_parameters()
andget_generated_parameters()
are removed. The random values for symbolic parameters for random testing are generated in the constructor of theContext
object now.get_and_gen_input_dis()
andget_and_gen_hashing_dis()
are merged and renamed togen_input_and_hashing_dis()
because they are always generated together. This also makes the result more deterministic (unrelated to the order of callingget_and_gen_input_dis()
andget_and_gen_hashing_dis()
).get_all_param_values()
is renamed toget_all_input_param_values()
.get_new_param_id()
for plain (input) symbolic and concrete ones,get_new_param_expression_id()
for symbolic expressions.get_num_parameters(), get_num_input_symbolic_parameters(), param_is_symbolic(), param_has_value(), param_is_expression(), get_param_wire()
. The wire is used inCircuitSeq
.get_param_masks()
for input parameter usage masks of each parameter expression.Cython
CircuitSeq
now takes only one parameter (the number of qubits).CircuitSeq
get_num_input_parameters(), get_num_total_parameters(), get_num_internal_parameters()
are removed.PyDAG
.EquivalenceSet::load_json
now takes an extra parameter specifying if it is from the Python verifier.QASMParser
context
toctx_
.Simulator
Context
for parameters now.Context
once now (previously twice).Utils
read_json_style_vector()
now also supportsstd::istream
(previously onlystd::stringstream
).to_string_with_precision()
fromutils.h
tostring_utils.h
and addsto_json_style_string_with_precision()
.