Skip to content

Commit

Permalink
Don't delete API docs for class aliases (Qiskit#815)
Browse files Browse the repository at this point in the history
Part of Qiskit#814. We shouldn't
be deleting attribute pages if they don't correspond to an owning class.

This PR also runs `npm run regen-apis`; as shown, this PR's logic change
only impacts Qiskit v1 docs.
  • Loading branch information
Eric-Arellano authored Feb 15, 2024
1 parent 829851c commit 2b1c26d
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 31 deletions.
1 change: 0 additions & 1 deletion docs/api/qiskit-ibm-provider/0.7/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,3 @@
],
"collapsed": true
}

1 change: 0 additions & 1 deletion docs/api/qiskit-ibm-runtime/0.18/_toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,3 @@
],
"collapsed": true
}

12 changes: 6 additions & 6 deletions docs/api/qiskit/dev/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ print([q.binary_probabilities() for q in job_result.quasi_dists])

## Estimator

| | |
| ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`BaseEstimator`](qiskit.primitives.BaseEstimator#qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator") | alias of `BaseEstimatorV1` |
| [`Estimator`](qiskit.primitives.Estimator "qiskit.primitives.Estimator")(\*\[, options]) | Reference implementation of [`BaseEstimator`](qiskit.primitives.BaseEstimator#qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator"). |
| [`BackendEstimator`](qiskit.primitives.BackendEstimator "qiskit.primitives.BackendEstimator")(backend\[, options, ...]) | Evaluates expectation value using Pauli rotation gates. |
| | |
| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| [`BaseEstimator`](qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator") | alias of `BaseEstimatorV1` |
| [`Estimator`](qiskit.primitives.Estimator "qiskit.primitives.Estimator")(\*\[, options]) | Reference implementation of [`BaseEstimator`](qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator"). |
| [`BackendEstimator`](qiskit.primitives.BackendEstimator "qiskit.primitives.BackendEstimator")(backend\[, options, ...]) | Evaluates expectation value using Pauli rotation gates. |

## EstimatorV2

Expand All @@ -241,7 +241,7 @@ print([q.binary_probabilities() for q in job_result.quasi_dists])

| | |
| ----------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
| [`BaseSampler`](qiskit.primitives.BaseSampler#qiskit.primitives.BaseSampler "qiskit.primitives.BaseSampler") | alias of `BaseSamplerV1` |
| [`BaseSampler`](qiskit.primitives.BaseSampler "qiskit.primitives.BaseSampler") | alias of `BaseSamplerV1` |
| [`Sampler`](qiskit.primitives.Sampler "qiskit.primitives.Sampler")(\*\[, options]) | Sampler class. |
| [`BackendSampler`](qiskit.primitives.BackendSampler "qiskit.primitives.BackendSampler")(backend\[, options, ...]) | A `BaseSampler` implementation that provides an interface for leveraging the sampler interface from any backend. |

Expand Down
12 changes: 12 additions & 0 deletions docs/api/qiskit/dev/qiskit.primitives.BaseEstimator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: BaseEstimator
description: API reference for qiskit.primitives.BaseEstimator
in_page_toc_min_heading_level: 1
python_api_type: attribute
python_api_name: qiskit.primitives.BaseEstimator
---

# BaseEstimator

alias of `BaseEstimatorV1`

12 changes: 12 additions & 0 deletions docs/api/qiskit/dev/qiskit.primitives.BaseSampler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: BaseSampler
description: API reference for qiskit.primitives.BaseSampler
in_page_toc_min_heading_level: 1
python_api_type: attribute
python_api_name: qiskit.primitives.BaseSampler
---

# BaseSampler

alias of `BaseSamplerV1`

2 changes: 1 addition & 1 deletion docs/api/qiskit/dev/qiskit.primitives.Estimator.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ python_api_name: qiskit.primitives.Estimator

Bases: `BaseEstimatorV1`\[`PrimitiveJob`\[[`EstimatorResult`](qiskit.primitives.EstimatorResult "qiskit.primitives.base.estimator_result.EstimatorResult")]]

Reference implementation of [`BaseEstimator`](qiskit.primitives.BaseEstimator#qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator").
Reference implementation of [`BaseEstimator`](qiskit.primitives.BaseEstimator "qiskit.primitives.BaseEstimator").

**Run Options**

Expand Down
2 changes: 1 addition & 1 deletion docs/api/qiskit/dev/qiskit.primitives.Sampler.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Bases: `BaseSamplerV1`\[`PrimitiveJob`\[[`SamplerResult`](qiskit.primitives.Samp

Sampler class.

[`Sampler`](#qiskit.primitives.Sampler "qiskit.primitives.Sampler") is a reference implementation of [`BaseSampler`](qiskit.primitives.BaseSampler#qiskit.primitives.BaseSampler "qiskit.primitives.BaseSampler").
[`Sampler`](#qiskit.primitives.Sampler "qiskit.primitives.Sampler") is a reference implementation of [`BaseSampler`](qiskit.primitives.BaseSampler "qiskit.primitives.BaseSampler").

**Run Options**

Expand Down
Binary file modified public/api/qiskit/dev/objects.inv
Binary file not shown.
24 changes: 22 additions & 2 deletions scripts/lib/api/mergeClassMembers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
import { describe, expect, test } from "@jest/globals";

import { mergeClassMembers } from "./mergeClassMembers";
import { HtmlToMdResultWithUrl } from "./HtmlToMdResult";

describe("mergeClassMembers", () => {
test("merge class members", async () => {
const results: Parameters<typeof mergeClassMembers>[0] = [
const results: HtmlToMdResultWithUrl[] = [
{
markdown: `## Attributes
Expand Down Expand Up @@ -130,7 +131,7 @@ Validate options.
});

test("merge class with methods already inlined", async () => {
const results: Parameters<typeof mergeClassMembers>[0] = [
const results: HtmlToMdResultWithUrl[] = [
{
markdown: `## Attributes
Expand Down Expand Up @@ -185,4 +186,23 @@ Inlined method
`);
expect(merged.length).toEqual(1);
});

test("keep members without an owning class", async () => {
// Regression test for https://github.com/Qiskit/documentation/issues/814.
const results: HtmlToMdResultWithUrl[] = [
{
markdown:
'<span id="baseestimator" />\n\n# BaseEstimator\n\nalias of `BaseEstimatorV1`\n',
meta: {
apiType: "attribute",
apiName: "qiskit.primitives.BaseEstimator",
},
images: [],
isReleaseNotes: false,
url: "/docs/api/qiskit/qiskit.primitives.BaseEstimator",
},
];
const merged = await mergeClassMembers(results);
expect(merged).toEqual(results);
});
});
28 changes: 9 additions & 19 deletions scripts/lib/api/mergeClassMembers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

import { includes, isEmpty, orderBy, reject } from "lodash";
import { includes, isEmpty, orderBy } from "lodash";
import { unified } from "unified";
import remarkParse from "remark-parse";
import remarkMdx from "remark-mdx";
Expand All @@ -32,21 +32,16 @@ export async function mergeClassMembers<T extends HtmlToMdResultWithUrl>(
const classes = resultsWithName.filter(
(result) => result.meta.apiType === "class",
);
const mergedMemberUrls = new Set();

for (const clazz of classes) {
const members = orderBy(
resultsWithName.filter((result) => {
if (
!includes(
["method", "property", "attribute", "function"],
result.meta.apiType,
)
)
return false;
return result.meta.apiName?.startsWith(`${clazz.meta.apiName}.`);
}),
(result) => result.meta.apiName,
const unsortedMembers = resultsWithName.filter(
(result) =>
includes(["method", "property", "attribute"], result.meta.apiType) &&
result.meta.apiName?.startsWith(`${clazz.meta.apiName}.`),
);
unsortedMembers.forEach((result) => mergedMemberUrls.add(result.url));
const members = orderBy(unsortedMembers, (result) => result.meta.apiName);

const attributesAndProps = members.filter(
(member) =>
Expand Down Expand Up @@ -94,12 +89,7 @@ export async function mergeClassMembers<T extends HtmlToMdResultWithUrl>(
}
}

// remove merged results
const finalResults = reject(results, (result) =>
includes(["method", "attribute", "property"], result.meta.apiType),
);

return finalResults;
return results.filter((result) => !mergedMemberUrls.has(result.url));
}

async function replaceMembersAfterTitle(
Expand Down

0 comments on commit 2b1c26d

Please sign in to comment.