-
Notifications
You must be signed in to change notification settings - Fork 7
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
Feat db jobs and results #118
base: dev
Are you sure you want to change the base?
Conversation
examples/notebooks/7_Data_Base.ipynb
Outdated
@@ -0,0 +1,939 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this file differently: the goal is not to have a DB per say, but to be able to save and load results. I have to checkout this file, but this could even be part of another notebook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stand by that, with the Result
integration, I would even have just a small mention in one of the first notebooks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we can rename it "Result management"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to "7_result_local_storage" 00c0a42
mpqp/core/instruction/breakpoint.py
Outdated
def __eq__(self, value: object) -> bool: | ||
if not isinstance(value, self.__class__): | ||
return False | ||
if self.to_dict() != value.to_dict(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove print ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done: 8f058e0
dict: A dictionary representation of the gate. | ||
""" | ||
result = {} | ||
for attr_name in dir(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be improved and factorized but as we discussed this can be done in another branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
if isinstance(val1, list) and isinstance(val2, list): | ||
try: | ||
from sympy import N | ||
|
||
val1_numeric = np.array( | ||
[[N(el) for el in row] for row in val1], dtype=complex | ||
) | ||
val2_numeric = np.array( | ||
[[N(el) for el in row] for row in val2], dtype=complex | ||
) | ||
if not np.allclose(val1_numeric, val2_numeric, atol=1e-7): | ||
return False | ||
except: | ||
if val1 != val2: | ||
return False | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be just a matrix_eq
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it can wait to be factored into another branch.
@@ -207,4 +259,4 @@ def caster(v: Expr | Complex) -> Expr | Complex: | |||
) | |||
|
|||
def __repr__(self) -> str: | |||
return f"UnitaryMatrix({one_lined_repr(getattr(self, 'matrix', ''))})" | |||
return f"UnitaryMatrix({one_lined_repr(self.matrix)})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we initially did this because not all gate definitions had the matrix
attribute, but I think I remember it is now the case so you change should be fine. Did you make sure it was ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes a UnitaryMatrix always have a matrix
args.append(f"symbols={self.symbols}") | ||
if self.basis_vectors_labels is not None: | ||
args.append(f"basis_vectors_labels={self.basis_vectors_labels}") | ||
return f"{type(self).__name__}({', '.join(args)})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loc seem to be the same for all reps, it could be factorized, on the other hand, since it's a single line, it would probably not improve that much the clarity or efficiency of the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is not the factorizer code, but I think it's better for understanding
else: | ||
coef = f"{self.coef}" | ||
return f"{coef}*{'@'.join(map(str,self.atoms))}" | ||
coef = f"{self.coef}*" if coef != 0 else "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be 1 instead of 0 ? (0 would mean I don't display the string at all or I just display "0", while 1 may mean I skip the coeff)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 5f36f46
@@ -123,7 +123,7 @@ def remove_results_with_results_db(results: Optional[list[DictDB] | DictDB]): | |||
|
|||
Example: | |||
>>> results = fetch_results_with_id(1) | |||
>>> remove_results_with_results_db(results) | |||
>>> remove_results_with_results_local_storage(results) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I didn't mind the db
in the function names, I just didn't really want to have it in the doc, but it's fine like this too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I am not convinced about putting different names everywhere. I think it's better to use only one
mpqp/noise/noise_model.py
Outdated
@@ -240,7 +256,7 @@ def __init__( | |||
self.check_dimension() | |||
|
|||
def check_dimension(self): | |||
if 0 < len(self.targets) < self.dimension: | |||
if len(self.targets) != 0 and len(self.targets) < self.dimension: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverse 5f36f46
rng.uniform(0, 2 * np.pi), | ||
rng.uniform(0, 2 * np.pi), | ||
rng.uniform(0, 2 * np.pi), | ||
np.round(rng.uniform(0, 2 * np.pi), 5), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we round ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for simplification in test
tests/core/test_circuit.py
Outdated
), | ||
], | ||
) | ||
def test_cbits_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_cbits_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int): | |
def test_cbits_undersized_static_circuit(circuit: QCircuit, expected_cbits: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 5f36f46
tests/core/test_circuit.py
Outdated
), | ||
], | ||
) | ||
def test_cbits_dynamic_to_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_cbits_dynamic_to_not_dynamic_circuit(circuit: QCircuit, expected_cbits: int): | |
def test_cbits_dynamic_toggled_off_undersized_circuit(circuit: QCircuit, expected_cbits: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done 5f36f46
from mpqp.all import * | ||
|
||
|
||
def generate_qcircuits(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
espèce de bourin x)x)x)x)x)
if db_version != DATABASE_VERSION: | ||
raise RuntimeError( | ||
f"Database version {db_version} is outdated. Expected {DATABASE_VERSION}. " | ||
"Please upgrade the database schema." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this done ? a user friendly way to migrate should be provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have only one version of db_version, so we don't need it, and I don't want to delay this branches.
@@ -78,7 +78,7 @@ def running_observable_job_ibm_simulated_devices( | |||
assert True | |||
|
|||
|
|||
if "--long-local" in sys.argv: | |||
if "--long-local" in sys.argv or "--long" in sys.argv: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this long thing about ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we forget to add this, we want to run this test on both --long
return self.to_dict() == other.to_dict() | ||
|
||
def to_dict(self): | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how manual of you ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can wait to be factored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc to polish, mostly to make sure it generates fine, and to include in the official doc + notebook to polish. A few remarks. Apart from that the coding part of the PR is almost done
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
Co-authored-by: Henri-ColibrITD <133855265+Henri-ColibrITD@users.noreply.github.com>
…ename test functions for clarity
No description provided.