Skip to content

Commit 6098735

Browse files
fixing the js getEndOfClassHeader
1 parent f39af67 commit 6098735

File tree

3 files changed

+116
-119
lines changed

3 files changed

+116
-119
lines changed

docs/_static/custom.js

+109-111
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,130 @@
11
window.onload = () => {
2-
// detect enums and make sure their description is easily to style
3-
document.querySelectorAll(".class").forEach(class_elt => {
4-
if (isEnum(class_elt)) {
5-
title = class_elt.querySelector("dt");
6-
title.innerHTML = title.innerHTML.replace(/, /g, "<span>, </span>");
7-
class_elt.classList.add("enum");
8-
}
9-
})
10-
11-
// remove the dark theme watermark added in js
12-
footer = document.querySelector("footer")
13-
dark_theme_link = (
14-
'<a href="https://github.com/MrDogeBro/sphinx_rtd_dark_mode">Dark theme</a>'
15-
+ ' provided by '
16-
+ '<a href="http://mrdogebro.com">MrDogeBro</a>.'
17-
)
18-
whenCondition(
19-
() => footer.innerHTML = footer.innerHTML.replace(dark_theme_link, ''),
20-
() => footer.innerHTML.includes(dark_theme_link)
21-
)
22-
23-
r = document.querySelector(':root')
24-
r.style.setProperty('--dark-link-color', '#80cb53');
25-
26-
// t = document.querySelector('html[data-theme="dark"] .wy-side-nav-search')
27-
// t.style.setProperty('background-color', '#0d0d0d');
28-
29-
// move the attribute and properties of a class to appear first in the class
30-
document.querySelectorAll(".py.class").forEach(pythonClass => {
31-
if (!isEnum(pythonClass)) {
32-
appendAfter = getEndOfClassHeader(pythonClass)
33-
pythonClass.querySelectorAll(".py.attribute").forEach(attribute => {
34-
appendAfter.insertAdjacentElement('afterend', attribute)
35-
appendAfter = attribute
36-
})
37-
pythonClass.querySelectorAll(".py.property").forEach(property => {
38-
appendAfter.insertAdjacentElement('afterend', property)
39-
appendAfter = property
40-
})
41-
}
42-
})
43-
44-
// move the constants of a module to appear first in the module
45-
document.querySelectorAll(".target").forEach(moduleMarker => {
46-
if (moduleMarker.id.startsWith("module-")) {
47-
appendAfter = moduleMarker
48-
sibling = moduleMarker.nextSibling
49-
for (; sibling; ) {
50-
next = sibling.nextSibling
51-
if (sibling.nodeName === "DL" && sibling.classList.contains("data")) {
52-
appendAfter.insertAdjacentElement('afterend', sibling)
53-
appendAfter = sibling
54-
}
55-
sibling = next
56-
}
2+
// detect enums and make sure their description is easily to style
3+
document.querySelectorAll(".class").forEach((class_elt) => {
4+
if (isEnum(class_elt)) {
5+
title = class_elt.querySelector("dt");
6+
title.innerHTML = title.innerHTML.replace(/, /g, "<span>, </span>");
7+
class_elt.classList.add("enum");
8+
}
9+
});
10+
11+
// remove the dark theme watermark added in js
12+
footer = document.querySelector("footer");
13+
dark_theme_link =
14+
'<a href="https://github.com/MrDogeBro/sphinx_rtd_dark_mode">Dark theme</a>' +
15+
" provided by " +
16+
'<a href="http://mrdogebro.com">MrDogeBro</a>.';
17+
whenCondition(
18+
() => (footer.innerHTML = footer.innerHTML.replace(dark_theme_link, "")),
19+
() => footer.innerHTML.includes(dark_theme_link)
20+
);
21+
22+
r = document.querySelector(":root");
23+
r.style.setProperty("--dark-link-color", "#80cb53");
24+
25+
// t = document.querySelector('html[data-theme="dark"] .wy-side-nav-search')
26+
// t.style.setProperty('background-color', '#0d0d0d');
27+
28+
// move the attribute and properties of a class to appear first in the class
29+
document.querySelectorAll(".py.class").forEach((pythonClass) => {
30+
if (!isEnum(pythonClass)) {
31+
appendAfter = getEndOfClassHeader(pythonClass);
32+
pythonClass.querySelectorAll(".py.attribute").forEach((attribute) => {
33+
appendAfter.insertAdjacentElement("afterend", attribute);
34+
appendAfter = attribute;
35+
});
36+
pythonClass.querySelectorAll(".py.property").forEach((property) => {
37+
appendAfter.insertAdjacentElement("afterend", property);
38+
appendAfter = property;
39+
});
40+
}
41+
});
42+
43+
// move the constants of a module to appear first in the module
44+
document.querySelectorAll(".target").forEach((moduleMarker) => {
45+
if (moduleMarker.id.startsWith("module-")) {
46+
appendAfter = moduleMarker;
47+
sibling = moduleMarker.nextSibling;
48+
for (; sibling; ) {
49+
next = sibling.nextSibling;
50+
if (sibling.nodeName === "DL" && sibling.classList.contains("data")) {
51+
appendAfter.insertAdjacentElement("afterend", sibling);
52+
appendAfter = sibling;
5753
}
58-
})
59-
60-
// move the abstract classes of a module to appear first in the module
61-
document.querySelectorAll(".section").forEach(section => {
62-
if (section.id.startsWith("module-")) {
63-
descriptionStart = section.querySelector("dl")
64-
appendAfter = descriptionStart.previousElementSibling
65-
sibling = descriptionStart
66-
for (; sibling; ) {
67-
next = sibling.nextElementSibling
68-
if (sibling.classList.contains("class") && isAbstract(sibling)) {
69-
appendAfter.insertAdjacentElement('afterend', sibling)
70-
appendAfter = sibling
71-
}
72-
sibling = next
73-
}
54+
sibling = next;
55+
}
56+
}
57+
});
58+
59+
// move the abstract classes of a module to appear first in the module
60+
document.querySelectorAll(".section").forEach((section) => {
61+
if (section.id.startsWith("module-")) {
62+
descriptionStart = section.querySelector("dl");
63+
appendAfter = descriptionStart.previousElementSibling;
64+
sibling = descriptionStart;
65+
for (; sibling; ) {
66+
next = sibling.nextElementSibling;
67+
if (sibling.classList.contains("class") && isAbstract(sibling)) {
68+
appendAfter.insertAdjacentElement("afterend", sibling);
69+
appendAfter = sibling;
7470
}
75-
})
76-
77-
78-
}
71+
sibling = next;
72+
}
73+
}
74+
});
75+
};
7976

8077
// const themeButton = document.querySelector('themeSwitcher')
8178
// themeButton.addEventListener('click', () => {
82-
//
79+
//
8380
// });
8481

85-
8682
function getEndOfClassHeader(elt) {
87-
admonition = elt.querySelectorAll(".admonition")
88-
if (admonition.length != 0) return admonition[admonition.length - 1]
89-
examples = elt.querySelectorAll("dd>div.doctest")
90-
if (examples.length != 0) return examples[examples.length - 1]
91-
return elt.querySelector(".field-list")
83+
admonition = elt.querySelectorAll(".admonition");
84+
if (admonition.length != 0) return admonition[admonition.length - 1];
85+
field_list = elt.querySelector(".class>dd>.field-list");
86+
if (field_list !== null) return elt.querySelector(".class>dd>.field-list");
87+
examples = elt.querySelectorAll(".class>dd>div.doctest");
88+
if (examples.length != 0) return examples[examples.length - 1];
89+
return elt;
9290
}
9391

9492
function isEnum(elt, explored = []) {
95-
id = elt.querySelector("dt").id
96-
if (explored.includes(id)) return false
97-
98-
explored.push(id)
99-
100-
parents = elt.querySelector("dd > p:first-child")
101-
if (parents && parents.innerHTML.includes("Enum")) {
102-
return true
103-
}
93+
id = elt.querySelector("dt").id;
94+
if (explored.includes(id)) return false;
95+
96+
explored.push(id);
10497

105-
parents_contain_enum = false
106-
elt.querySelectorAll("dd > p:first-child > a").forEach(link => {
107-
parent_id = link.href.split("#")[1]
108-
new_elt = document.querySelector(`.class:has([id='${parent_id}'])`)
109-
if (new_elt && isEnum(new_elt, explored)) parents_contain_enum = true
110-
})
98+
parents = elt.querySelector("dd > p:first-child");
99+
if (parents && parents.innerHTML.includes("Enum")) {
100+
return true;
101+
}
111102

112-
return parents_contain_enum
103+
parents_contain_enum = false;
104+
elt.querySelectorAll("dd > p:first-child > a").forEach((link) => {
105+
parent_id = link.href.split("#")[1];
106+
new_elt = document.querySelector(`.class:has([id='${parent_id}'])`);
107+
if (new_elt && isEnum(new_elt, explored)) parents_contain_enum = true;
108+
});
109+
110+
return parents_contain_enum;
113111
}
114112

115113
function isAbstract(elt) {
116-
parents = elt.querySelector("dd > p:first-child")
117-
if (parents && parents.innerHTML.includes("ABC")) {
118-
return true
119-
}
120-
return false
114+
parents = elt.querySelector("dd > p:first-child");
115+
if (parents && parents.innerHTML.includes("ABC")) {
116+
return true;
117+
}
118+
return false;
121119
}
122120

123121
function whenCondition(action, condition) {
124-
function watcher() {
125-
if(condition()) {
126-
action()
127-
clearInterval(interval)
128-
}
122+
function watcher() {
123+
if (condition()) {
124+
action();
125+
clearInterval(interval);
129126
}
130-
131-
interval = setInterval(watcher, 50);
132-
}
127+
}
128+
129+
interval = setInterval(watcher, 50);
130+
}

mpqp/execution/connection/aws_connection.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def setup_aws_braket_account() -> tuple[str, list[Any]]:
2626
success, cancelled, or error, ...) and an empty list. The list is
2727
included for consistency with the existing code structure.
2828
"""
29+
from braket.aws import AwsSession
2930

3031
already_configured = get_env_variable("BRAKET_CONFIGURED") == "True"
3132

@@ -115,9 +116,9 @@ def get_braket_device(device: AWSDevice) -> "BraketDevice":
115116
from braket.devices import LocalSimulator
116117

117118
return LocalSimulator()
118-
from botocore.exceptions import NoRegionError
119-
from braket.aws import AwsDevice
120119
import boto3
120+
from botocore.exceptions import NoRegionError
121+
from braket.aws import AwsDevice, AwsSession
121122

122123
try:
123124
braket_client = boto3.client("braket", region_name=device.get_region())

mpqp/execution/providers/aws.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@
1111
from braket.tasks import GateModelQuantumTaskResult, QuantumTask
1212
from typeguard import typechecked
1313

14-
from mpqp import QCircuit, Language
14+
from mpqp import Language, QCircuit
1515
from mpqp.core.instruction.measurement import (
16-
ExpectationMeasure,
1716
BasisMeasure,
17+
ExpectationMeasure,
1818
Observable,
1919
)
2020
from mpqp.execution.connection.aws_connection import get_braket_device
2121
from mpqp.execution.devices import AWSDevice
2222
from mpqp.execution.job import Job, JobStatus, JobType
2323
from mpqp.execution.result import Result, Sample, StateVector
24-
from mpqp.tools.errors import AWSBraketRemoteExecutionError
25-
from mpqp.execution.job import Job, JobType, JobStatus
26-
from mpqp.tools.errors import DeviceJobIncompatibleError
24+
from mpqp.tools.errors import AWSBraketRemoteExecutionError, DeviceJobIncompatibleError
2725

2826
# TODO: types are messed up here, fix it
2927

@@ -117,7 +115,7 @@ def submit_job_braket(job: Job) -> tuple[str, QuantumTask]:
117115
def extract_result(
118116
braket_result: GateModelQuantumTaskResult,
119117
job: Optional[Job] = None,
120-
device: Optional[AWSDevice] = AWSDevice.BRAKET_LOCAL_SIMULATOR,
118+
device: AWSDevice = AWSDevice.BRAKET_LOCAL_SIMULATOR,
121119
) -> Result:
122120
"""
123121
Constructs a Result from the result given by the run with Braket.

0 commit comments

Comments
 (0)